package com.yhy.module.core.dal.mysql.workbench;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yhy.module.core.dal.dataobject.workbench.WbFeeItemDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 工作台-取费模板快照 Mapper
 *
 * @author yihuiyong
 */
@Mapper
public interface WbFeeItemMapper extends BaseMapperX<WbFeeItemDO> {

    /**
     * 根据单位工程ID查询取费模板
     */
    default List<WbFeeItemDO> selectByCompileTreeId(Long compileTreeId) {
        return selectList(new LambdaQueryWrapperX<WbFeeItemDO>()
                .eq(WbFeeItemDO::getCompileTreeId, compileTreeId)
                .orderByAsc(WbFeeItemDO::getSortOrder));
    }

    /**
     * 根据单位工程ID和费率模式ID查询取费模板
     */
    default List<WbFeeItemDO> selectByCompileTreeIdAndCatalogItemId(Long compileTreeId, Long catalogItemId) {
        return selectList(new LambdaQueryWrapperX<WbFeeItemDO>()
                .eq(WbFeeItemDO::getCompileTreeId, compileTreeId)
                .eq(WbFeeItemDO::getCatalogItemId, catalogItemId)
                .orderByAsc(WbFeeItemDO::getSortOrder));
    }

    /**
     * 根据单位工程ID和费率项ID查询
     */
    default List<WbFeeItemDO> selectByRateItemId(Long compileTreeId, Long rateItemId) {
        return selectList(new LambdaQueryWrapperX<WbFeeItemDO>()
                .eq(WbFeeItemDO::getCompileTreeId, compileTreeId)
                .eq(WbFeeItemDO::getRateItemId, rateItemId)
                .orderByAsc(WbFeeItemDO::getSortOrder));
    }

    /**
     * 根据单位工程ID删除所有取费模板数据
     */
    default int deleteByCompileTreeId(Long compileTreeId) {
        return delete(new LambdaQueryWrapperX<WbFeeItemDO>()
                .eq(WbFeeItemDO::getCompileTreeId, compileTreeId));
    }

    /**
     * 根据单位工程ID和费率模式ID删除取费模板数据
     */
    default int deleteByCompileTreeIdAndCatalogItemId(Long compileTreeId, Long catalogItemId) {
        return delete(new LambdaQueryWrapperX<WbFeeItemDO>()
                .eq(WbFeeItemDO::getCompileTreeId, compileTreeId)
                .eq(WbFeeItemDO::getCatalogItemId, catalogItemId));
    }

    /**
     * 根据来源ID查询（用于ID映射）
     */
    default WbFeeItemDO selectBySourceId(Long compileTreeId, Long sourceId) {
        return selectOne(new LambdaQueryWrapperX<WbFeeItemDO>()
                .eq(WbFeeItemDO::getCompileTreeId, compileTreeId)
                .eq(WbFeeItemDO::getSourceId, sourceId));
    }
}
