package com.ruoyi.system.mapper.house;

import com.ruoyi.system.domain.changerecord.annotation.DataChangeLog;
import com.ruoyi.system.domain.changerecord.enums.OperationType;
import com.ruoyi.system.domain.changerecord.enums.SubjectType;
import com.ruoyi.system.domain.house.HouseResourceBusinessEntityInfoMapping;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface HouseResourceBusinessEntityInfoMappingMapper {

    // 新增关联关系；同时给房源侧和经营主体侧各记录一条修改日志
    @DataChangeLog(subjectType = SubjectType.HOUSE_RESOURCE, operation = OperationType.UPDATE, idExpr = "houseResourceId")
    @DataChangeLog(subjectType = SubjectType.BUSINESS_ENTITY_INFO, operation = OperationType.UPDATE, idExpr = "businessEntityInfoId")
    void insert(HouseResourceBusinessEntityInfoMapping houseResourceBusinessEntityInfoMapping);

    // 按 (houseResourceId, businessEntityInfoId) 逻辑删除关联；双侧各一条修改日志
    @DataChangeLog(subjectType = SubjectType.HOUSE_RESOURCE, operation = OperationType.UPDATE, idExpr = "houseResourceId")
    @DataChangeLog(subjectType = SubjectType.BUSINESS_ENTITY_INFO, operation = OperationType.UPDATE, idExpr = "businessEntityInfoId")
    void deleteByHouseResourceIdBusinessEntityInfoId(
            @Param("houseResourceId") String houseResourceId,
            @Param("businessEntityInfoId") String businessEntityInfoId);

    // 按 houseResourceId 批量逻辑删除；房源侧直接取参数，经营主体侧需要预查
    @DataChangeLog(subjectType = SubjectType.HOUSE_RESOURCE, operation = OperationType.UPDATE, idExpr = "houseResourceId")
    @DataChangeLog(
            subjectType = SubjectType.BUSINESS_ENTITY_INFO,
            operation = OperationType.UPDATE,
            preLoadMapper = "com.ruoyi.system.mapper.house.HouseResourceBusinessEntityInfoMappingMapper.selectByHouseResourceId",
            idExpr = "@preload[*].businessEntityInfoId"
    )
    void deleteByHouseResourceId(@Param("houseResourceId") String houseResourceId);

    List<HouseResourceBusinessEntityInfoMapping> selectByBusinessEntityInfoId(@Param("businessEntityInfoId") String businessEntityInfoId);

    List<HouseResourceBusinessEntityInfoMapping> selectByHouseResourceId(@Param("houseResourceId") String houseResourceId);

    List<HouseResourceBusinessEntityInfoMapping> selectByHouseResourceIds(@Param("houseResourceIds") List<String> houseResourceIds);
}
