package com.backendsys.modules.ai.chat.controller;

import com.backendsys.modules.ai.chat.entity.Chat;
import com.backendsys.modules.ai.chat.entity.ChatHistory;
import com.backendsys.modules.ai.chat.service.ChatHistoryService;
import com.backendsys.modules.common.config.security.utils.SecurityUtil;
import com.backendsys.modules.common.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Validated
@RestController
@Tag(name = "AI对话历史")
public class ChatHistoryController {

    @Autowired
    private ChatHistoryService chatHistoryService;

    @Operation(summary = "获取我的对话历史列表")
    @PreAuthorize("@sr.hasPermission('31')")
    @GetMapping("/api/ai/chat/getChatHistoryList")
    public Result getChatHistoryList() {
        ChatHistory history = new ChatHistory();
        history.setUser_id(SecurityUtil.getUserId());
        history.setDel_flag(-1);
        return Result.success().put("data", chatHistoryService.selectChatHistoryList(history));
    }

    @Operation(summary = "删除我的对话历史及内容 (软删除)")
    @PreAuthorize("@sr.hasPermission('31')")
    @DeleteMapping("/api/ai/chat/deleteChatHistory")
    public Result deleteChatHistory(@Validated(ChatHistory.Delete.class) @RequestBody ChatHistory chatHistory) {
        return Result.success().put("data", chatHistoryService.deleteChatHistory(chatHistory));
    }

}
