package com.example.system.controller;


import com.example.system.common.AiResult;
import com.example.system.dto.AiChatRequestDTO;
import com.example.system.common.AiChat;
import com.example.system.service.AiChatService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * AI竞赛助手控制器
 */
@RestController
@CrossOrigin
@RequestMapping("/api/ai-chat")
public class AiChatController {

    private static final Logger logger = LoggerFactory.getLogger(AiChatController.class);

    @Resource
    private AiChatService aiChatService;

    /**
     * 与AI助手对话
     *
     * @param requestDTO 请求DTO
     * @return 对话结果
     */
    @PostMapping("/chat")
    public AiResult<String> chat(@RequestBody AiChatRequestDTO requestDTO) {
        logger.info("接收到AI对话请求: userId={}", requestDTO.getUserId());
        return aiChatService.chat(requestDTO);
    }

    /**
     * 获取用户最近的会话记录
     *
     * @param userId 用户ID
     * @return 会话记录列表
     */
    @GetMapping("/history/{userId}")
    public AiResult<List<AiChat>> getRecentChats(@PathVariable Long userId) {
        logger.info("获取会话历史: userId={}", userId);
        return aiChatService.getRecentChats(userId);
    }
}

