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.WbUnifiedFeeSettingDO;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;

/**
 * 工作台-统一取费设置快照 Mapper
 *
 * @author yihuiyong
 */
@Mapper
public interface WbUnifiedFeeSettingMapper extends BaseMapperX<WbUnifiedFeeSettingDO> {

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

    /**
     * 根据单位工程ID和父节点ID查询子节点
     */
    default List<WbUnifiedFeeSettingDO> selectByParentId(Long compileTreeId, Long parentId) {
        return selectList(new LambdaQueryWrapperX<WbUnifiedFeeSettingDO>()
                .eq(WbUnifiedFeeSettingDO::getCompileTreeId, compileTreeId)
                .eq(WbUnifiedFeeSettingDO::getParentId, parentId)
                .orderByAsc(WbUnifiedFeeSettingDO::getSortOrder));
    }

    /**
     * 根据单位工程ID查询根节点（目录节点）
     */
    default List<WbUnifiedFeeSettingDO> selectRootNodes(Long compileTreeId) {
        return selectList(new LambdaQueryWrapperX<WbUnifiedFeeSettingDO>()
                .eq(WbUnifiedFeeSettingDO::getCompileTreeId, compileTreeId)
                .isNull(WbUnifiedFeeSettingDO::getParentId)
                .orderByAsc(WbUnifiedFeeSettingDO::getSortOrder));
    }

    /**
     * 根据单位工程ID和节点类型查询
     */
    default List<WbUnifiedFeeSettingDO> selectByNodeType(Long compileTreeId, String nodeType) {
        return selectList(new LambdaQueryWrapperX<WbUnifiedFeeSettingDO>()
                .eq(WbUnifiedFeeSettingDO::getCompileTreeId, compileTreeId)
                .eq(WbUnifiedFeeSettingDO::getNodeType, nodeType)
                .orderByAsc(WbUnifiedFeeSettingDO::getSortOrder));
    }

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

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

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

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