package cn.qinys.platform.mobile.controller;

import cn.qinys.platform.base.response.Result;
import cn.qinys.platform.mobile.req.ChatHistoryReq;
import cn.qinys.platform.mobile.req.ChatReq;
import cn.qinys.platform.mobile.resp.ChatResp;
import cn.qinys.platform.mobile.service.ChatService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import cn.qinys.platform.mobile.resp.ChatHistoryResp;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dgapi/mobile/chat")
public class ChatController {

    @Resource
    private ChatService chatService;

    /**
     * 发送消息
     */
    @PostMapping
    public Result<ChatResp> chat(@RequestBody @Valid ChatReq req) {
        String reply = chatService.chat(req);
        ChatResp resp = new ChatResp();
        resp.setReply(reply);
        return new Result<>(resp);
    }

    /**
     * 获取聊天历史（按许愿树过滤）
     */
    @GetMapping("/history")
    public Result<Page<ChatHistoryResp>> history(@Valid ChatHistoryReq req) {
        Page<ChatHistoryResp> resp = chatService.getHistory(req);
        return new Result<>(resp);
    }
}
