package com.lesingle.creation.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lesingle.creation.entity.SysConfig;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 系统配置 Mapper 接口
 */
@Mapper
public interface SysConfigMapper extends BaseMapper<SysConfig> {

    /**
     * 根据租户 ID 和配置键查询配置
     *
     * @param tenantId 租户 ID
     * @param configKey 配置键
     * @return 配置实体
     */
    @Select("SELECT * FROM t_sys_config WHERE tenant_id = #{tenantId} AND config_key = #{configKey} AND deleted = 0")
    SysConfig selectByKey(@Param("tenantId") Long tenantId, @Param("configKey") String configKey);

    /**
     * 根据租户 ID 和配置键查询配置（排除指定 ID）
     *
     * @param tenantId 租户 ID
     * @param configKey 配置键
     * @param excludeId 排除的 ID
     * @return 配置实体
     */
    @Select("SELECT * FROM t_sys_config WHERE tenant_id = #{tenantId} AND config_key = #{configKey} AND id != #{excludeId} AND deleted = 0")
    SysConfig selectByKeyExclude(@Param("tenantId") Long tenantId, @Param("configKey") String configKey, @Param("excludeId") Long excludeId);
}
