<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.xyzh.ai.mapper.AiAgentConfigMapper">

    <!-- 基础结果映射 -->
    <resultMap id="BaseResultMap" type="org.xyzh.common.dto.ai.TbAiAgentConfig">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="avatar" property="avatar" jdbcType="VARCHAR"/>
        <result column="system_prompt" property="systemPrompt" jdbcType="LONGVARCHAR"/>
        <result column="model_name" property="modelName" jdbcType="VARCHAR"/>
        <result column="model_provider" property="modelProvider" jdbcType="VARCHAR"/>
        <result column="temperature" property="temperature" jdbcType="DECIMAL"/>
        <result column="max_tokens" property="maxTokens" jdbcType="INTEGER"/>
        <result column="top_p" property="topP" jdbcType="DECIMAL"/>
        <result column="status" property="status" jdbcType="INTEGER"/>
        <result column="creator" property="creator" jdbcType="VARCHAR"/>
        <result column="updater" property="updater" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
        <result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
    </resultMap>

    <!-- 基础字段 -->
    <sql id="Base_Column_List">
        id, name, avatar, system_prompt, model_name, model_provider, temperature, 
        max_tokens, top_p, status, creator, updater, create_time, update_time, 
        delete_time, deleted
    </sql>

    <!-- 通用条件 -->
    <sql id="Where_Clause">
        <where>
            deleted = 0
            <if test="name != null and name != ''">
                AND name LIKE CONCAT('%', #{name}, '%')
            </if>
            <if test="modelName != null and modelName != ''">
                AND model_name = #{modelName}
            </if>
            <if test="modelProvider != null and modelProvider != ''">
                AND model_provider = #{modelProvider}
            </if>
            <if test="status != null">
                AND status = #{status}
            </if>
        </where>
    </sql>

    <!-- selectAiAgentConfigs -->
    <select id="selectAiAgentConfigs" resultMap="BaseResultMap">
        SELECT 
        <include refid="Base_Column_List"/>
        FROM tb_ai_agent_config
        <include refid="Where_Clause"/>
        ORDER BY create_time DESC
    </select>

</mapper>
