<?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="com.example.system.mapper.AiChatMapper">
    <insert id="insert" parameterType="com.example.system.common.AiChat">
        INSERT INTO ai_competition_chat
        ( user_id, user_question, ai_response, chat_time, competition_type, is_deleted)
        VALUES
            ( #{userId}, #{userQuestion}, #{aiResponse}, #{chatTime}, #{competitionType}, #{isDeleted})
    </insert>


    <select id="selectById" resultType="com.example.system.common.AiChat">
        SELECT * FROM ai_competition_chat WHERE chat_id = #{chatId}
    </select>

    <select id="selectRecentByUserId" resultType="com.example.system.common.AiChat">
        SELECT * FROM ai_competition_chat
        WHERE user_id = #{userId}
        ORDER BY chat_time DESC
            LIMIT #{limit}
    </select>
</mapper>
