package com.supervision.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.supervision.domain.IrSession;
import com.supervision.domain.IrSessionHistory;
import com.supervision.service.IrSessionService;
import com.supervision.vo.session.CreateAjResVO;
import com.supervision.vo.session.FinishSessionVO;
import com.supervision.vo.session.NewSessionReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;

@Slf4j
@Api(tags = "会话管理")
@RestController
@RequestMapping("session")
@RequiredArgsConstructor
public class SessionController {

    private final IrSessionService irSessionService;

    @ApiOperation("创建案件前,根据关键词查找案件ID或名称")
    @GetMapping("queryAjBeforeCreatSession")
    public List<CreateAjResVO> queryAjBeforeCreatSession(String keyword){
        return irSessionService.queryAjBeforeCreatSession(keyword);
    }

    @ApiOperation("创建新的会话")
    @PostMapping("createNewSession")
    public IrSession createNewSession(@RequestBody NewSessionReqVO newSessionReqVO) {
        return irSessionService.createNewSession(newSessionReqVO);
    }

    @ApiOperation("分页获取会话列表")
    @GetMapping("querySessionPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sessionName", value = "模糊搜索", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "pageNum", required = true, dataType = "Integer", paramType = "query")
    })
    public IPage<IrSession> querySessionPage(String sessionName, Integer pageSize, Integer pageNum) {
        return irSessionService.querySessionPage(sessionName, pageSize, pageNum);
    }

    @ApiOperation("结束会话")
    @PostMapping("finishSession")
    public void finishSession(@RequestBody FinishSessionVO finishSessionVO) {
        irSessionService.finishSession(finishSessionVO);
    }

    @ApiOperation("查询会话历史记录列表(结束时评分选择使用,非对话框内容)")
    @GetMapping("querySessionHistory")
    public List<IrSessionHistory> querySessionHistory(@NotBlank(message = "会话ID不能为空") String sessionId) {
        return irSessionService.querySessionHistory(sessionId);
    }

    @ApiOperation("删除会话记录")
    @PostMapping("deleteSession")
    public void deleteSession(@NotBlank(message = "会话ID不能为空") @RequestBody List<String> sessionList) {
        irSessionService.deleteSession(sessionList);
    }


}
