package com.jeesharp.business.modules.ai.controller;

import com.jeesharp.business.modules.ai.application.AiChatSessionApplicationService;
import com.jeesharp.business.modules.ai.dto.AiChatSessionSaveDTO;
import com.jeesharp.business.modules.ai.entity.AiChatSession;
import com.jeesharp.business.modules.ai.vo.AiChatSessionInfoVO;
import com.jeesharp.business.modules.ai.vo.AiChatSessionListVO;
import com.jeesharp.business.modules.ai.vo.AiChatSessionQueryVO;
import com.jeesharp.framework.pojo.AjaxResult;
import com.jeesharp.framework.pojo.Page;
import com.jeesharp.framework.pojo.query.PageRespVO;
import com.jeesharp.framework.web.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/ai/chatSession/v1")
@Tag(name = "AI客服-会话")
@AllArgsConstructor
public class AiChatSessionController extends BaseController {

    private final AiChatSessionApplicationService aiChatSessionApplicationService;

    @Operation(summary = "获取详情")
    @PreAuthorize("@ss.hasPermission('manager:business:ai:chatSession:info')")
    @GetMapping("info")
    public AjaxResult<AiChatSessionInfoVO> info(@RequestParam("id") String id) {
        return AjaxResult.okData(aiChatSessionApplicationService.get(id));
    }

    @Operation(summary = "分页列表")
    @PreAuthorize("@ss.hasPermission('manager:business:ai:chatSession:list')")
    @PostMapping("list")
    public AjaxResult<PageRespVO<AiChatSessionListVO>> list(@RequestBody AiChatSessionQueryVO query) {
        return AjaxResult.okData(aiChatSessionApplicationService.findPage(new Page<>(query), query));
    }

    @Operation(summary = "保存")
    @PreAuthorize("@ss.hasPermission('manager:business:ai:chatSession:save')")
    @PostMapping("save")
    public AjaxResult<Void> save(@RequestBody @Valid AiChatSessionSaveDTO dto) {
        aiChatSessionApplicationService.save(dto);
        return AjaxResult.ok("保存成功");
    }

    @Operation(summary = "删除")
    @PreAuthorize("@ss.hasPermission('manager:business:ai:chatSession:delete')")
    @GetMapping("delete")
    public AjaxResult<Void> delete(@RequestParam("ids") String ids) {
        aiChatSessionApplicationService.delete(ids);
        return AjaxResult.ok("删除成功");
    }
}
