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

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yhy.module.core.dal.dataobject.calcbaserate.CalcBaseRateCatalogDO;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;

/**
 * 基数费率目录树 Mapper
 *
 * @author yhy
 */
@Mapper
public interface CalcBaseRateCatalogMapper extends BaseMapperX<CalcBaseRateCatalogDO> {

    /**
     * 查询所有节点（树形结构）
     */
    default List<CalcBaseRateCatalogDO> selectList() {
        return selectList(new LambdaQueryWrapper<CalcBaseRateCatalogDO>()
                .orderByAsc(CalcBaseRateCatalogDO::getSortOrder));
    }

    /**
     * 根据父节点ID查询子节点
     */
    default List<CalcBaseRateCatalogDO> selectListByParentId(Long parentId) {
        return selectList(new LambdaQueryWrapper<CalcBaseRateCatalogDO>()
                .eq(CalcBaseRateCatalogDO::getParentId, parentId)
                .orderByAsc(CalcBaseRateCatalogDO::getSortOrder));
    }

    /**
     * 根据编码查询
     */
    default CalcBaseRateCatalogDO selectByCode(String code) {
        return selectOne(CalcBaseRateCatalogDO::getCode, code);
    }

    /**
     * 查询同级节点（用于排序）
     */
    default List<CalcBaseRateCatalogDO> selectSiblings(Long parentId) {
        return selectList(new LambdaQueryWrapper<CalcBaseRateCatalogDO>()
                .eq(parentId != null, CalcBaseRateCatalogDO::getParentId, parentId)
                .isNull(parentId == null, CalcBaseRateCatalogDO::getParentId)
                .orderByAsc(CalcBaseRateCatalogDO::getSortOrder));
    }

    /**
     * 根据节点类型查询
     */
    default CalcBaseRateCatalogDO selectByNodeType(String nodeType) {
        return selectOne(CalcBaseRateCatalogDO::getNodeType, nodeType);
    }
}
