package jnpf.helpailog.controller;

import com.github.pagehelper.PageInfo;
import jnpf.base.ActionResult;
import jnpf.base.UserInfo;
import jnpf.base.vo.PageListVO;
import jnpf.helpailog.service.FtbHelpAiChatLogService;
import jnpf.model.helpailog.dto.HelpAiLogDto;
import jnpf.model.helpailog.dto.HelpAiLogReq;
import jnpf.model.helpailog.po.FtbHelpAiChatLog;
import jnpf.util.FtbUtil;
import jnpf.util.UserProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 帮助ai 聊天记录
 *
 * @author xgl
 */
@RestController
@Slf4j
@RequestMapping("/help-ai-chat-log")
public class HelpAiLogController {


    @Autowired
    private UserProvider userProvider;

    @Autowired
    private FtbHelpAiChatLogService ftbHelpAiChatLogService;

    /**
     * @param dto
     * @return
     */
    @PostMapping("/record")
    public ActionResult<Boolean> record(@Validated @RequestBody HelpAiLogDto dto) {
        UserInfo userInfo = userProvider.get();
        String userId = userInfo.getUserId();
        String tenantId = userInfo.getTenantId();
        String userName = userInfo.getUserName();
        ftbHelpAiChatLogService.record(dto.convertToEntity(userId, userName, tenantId));
        return ActionResult.success();
    }


    /**
     * 分页查询聊天
     *
     * @param req
     * @return
     */
    @GetMapping("/list")
    public ActionResult<PageListVO<FtbHelpAiChatLog>> pageLists(HelpAiLogReq req) {
        PageInfo<FtbHelpAiChatLog> pageVo = ftbHelpAiChatLogService.getPageList(req);
        return ActionResult.page(pageVo.getList(), FtbUtil.getPagination(pageVo));
    }

}
