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

import com.jeesharp.business.modules.ai.application.AiChatMessageApplicationService;
import com.jeesharp.business.modules.ai.dto.AiChatMessageSaveDTO;
import com.jeesharp.business.modules.ai.entity.AiChatMessage;
import com.jeesharp.business.modules.ai.vo.AiChatMessageInfoVO;
import com.jeesharp.business.modules.ai.vo.AiChatMessageListVO;
import com.jeesharp.business.modules.ai.vo.AiChatMessageQueryVO;
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/chatMessage/v1")
@Tag(name = "AI客服-消息")
@AllArgsConstructor
public class AiChatMessageController extends BaseController {

    private final AiChatMessageApplicationService aiChatMessageApplicationService;

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

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

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

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