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.ConfigUnitResourceFieldDO;
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 ConfigUnitResourceFieldMapper extends BaseMapperX<ConfigUnitResourceFieldDO> {

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

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

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