package tech.easyflow.skill.mapper;

import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tech.easyflow.skill.entity.SkillCategory;

import java.math.BigInteger;
import java.util.List;

/**
 * Skill 分类 Mapper。
 */
public interface SkillCategoryMapper extends BaseMapper<SkillCategory> {

    /**
     * 按稳定顺序锁定租户内完整分类树，串行化分类结构变更。
     *
     * @param tenantId 租户 ID
     * @return 已锁定的分类列表
     */
    @Select("SELECT id,tenant_id AS tenantId,parent_id AS parentId,category_name AS categoryName," +
            "level_no AS levelNo,ancestors,sort_no AS sortNo,status,created,created_by AS createdBy," +
            "modified,modified_by AS modifiedBy FROM tb_skill_category " +
            "WHERE tenant_id=#{tenantId} ORDER BY id FOR UPDATE")
    List<SkillCategory> selectTenantTreeForUpdate(@Param("tenantId") BigInteger tenantId);
}
