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

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import com.yhy.module.core.dal.dataobject.config.ConfigUnitFieldDO;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ConfigUnitFieldMapper extends BaseMapperX<ConfigUnitFieldDO> {

    default List<ConfigUnitFieldDO> selectListByCatalogItemId(Long catalogItemId) {
        return selectList(ConfigUnitFieldDO::getCatalogItemId, catalogItemId);
    }

    @Select("SELECT COALESCE(MAX(sort_order), 0) FROM yhy_config_unit_field WHERE catalog_item_id = #{catalogItemId} AND deleted = 0")
    Integer selectMaxSortOrder(@Param("catalogItemId") Long catalogItemId);

    default List<ConfigUnitFieldDO> selectListByCatalogItemIdAndSortOrderGe(Long catalogItemId, Integer sortOrder) {
        return selectList(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<ConfigUnitFieldDO>()
                .eq(ConfigUnitFieldDO::getCatalogItemId, catalogItemId)
                .ge(ConfigUnitFieldDO::getSortOrder, sortOrder)
                .orderByAsc(ConfigUnitFieldDO::getSortOrder));
    }
}
