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.WbCategoryTreeDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 工作台-工料机机类树快照 Mapper
 *
 * @author yihuiyong
 */
@Mapper
public interface WbCategoryTreeMapper extends BaseMapperX<WbCategoryTreeDO> {

    /**
     * 根据单位工程ID查询机类树
     */
    default List<WbCategoryTreeDO> selectByCompileTreeId(Long compileTreeId) {
        return selectList(new LambdaQueryWrapperX<WbCategoryTreeDO>()
                .eq(WbCategoryTreeDO::getCompileTreeId, compileTreeId)
                .orderByAsc(WbCategoryTreeDO::getSortOrder));
    }

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

    /**
     * 根据单位工程ID删除所有机类树数据
     */
    default int deleteByCompileTreeId(Long compileTreeId) {
        return delete(new LambdaQueryWrapperX<WbCategoryTreeDO>()
                .eq(WbCategoryTreeDO::getCompileTreeId, compileTreeId));
    }

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