package shop.alien.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import shop.alien.entity.store.LawyerAiInteractionLog;
import shop.alien.entity.store.vo.LawyerAiInteractionLogVo;

import java.util.List;

/**
 * <p>
 * AI交互日志 Mapper 接口
 * </p>
 *
 * @author system
 * @since 2025-01-XX
 */
@Mapper
public interface LawyerAiInteractionLogMapper extends BaseMapper<LawyerAiInteractionLog> {


    @Insert(
            "INSERT " +
            "INTO " +
            "lawyer_ai_interaction_log " +
            "(" +
            "client_user_id, " +
            "conversation_id, " +
            "query_text, " +
            "response_text, " +
            "problem_scenario_id, " +
            "interaction_time, " +
            "delete_flag, " +
            "created_time, " +
            "updated_time" +
            ")" +
            " VALUES " +
            "(" +
            "#{clientUserId}, " +
            "#{conversationId}, " +
            "#{queryText}, " +
            "#{responseText}, " +
            "#{problemScenarioId}, " +
            "#{interactionTime}, " +
            "#{deleteFlag}, " +
            "#{createdTime}, " +
            "#{updatedTime}" +
            ")"
    )
    int insertLog(LawyerAiInteractionLogVo log);


    @Update("<script>" +
            "UPDATE " +
            "lawyer_ai_interaction_log " +
            "<set>" +
            "<if test='clientUserId != null'>client_user_id = #{clientUserId},</if>" +
            "<if test='conversationId != null'>conversation_id = #{conversationId},</if>" +
            "<if test='queryText != null'>query_text = #{queryText},</if>" +
            "<if test='responseText != null'>response_text = #{responseText},</if>" +
            "<if test='problemScenarioId != null'>problem_scenario_id = #{problemScenarioId},</if>" +
            "<if test='interactionTime != null'>interaction_time = #{interactionTime},</if>" +
            "<if test='deleteFlag != null'>delete_flag = #{deleteFlag},</if>" +
            "<if test='createdTime != null'>created_time = #{createdTime},</if>" +
            "<if test='updatedTime != null'>updated_time = #{updatedTime},</if>" +
            "</set>" +
            "WHERE id = #{id}" +
            "</script>")

    int updateLog(LawyerAiInteractionLogVo log);




    @Select("<script>" +
            "SELECT " +
            "id, " +
            "client_user_id," +
            "conversation_id," +
            "query_text," +
            "response_text," +
            "problem_scenario_id," +
            "interaction_time," +
            "delete_flag, " +
            "created_time," +
            "updated_time, " +
            "scene_id " +
            "FROM " +
            "lawyer_ai_interaction_log " +
            "WHERE " +
            "client_user_id = #{clientUserId} " +
            "AND delete_flag = 0 " +
            "ORDER BY created_time DESC " +
            "</script>")
    List<LawyerAiInteractionLog> getLogList(
            @Param("clientUserId") Integer clientUserId,
            @Param("page") Integer page,
            @Param("size") Integer size);



}

