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

import com.jeesharp.business.modules.ai.application.AiFaqApplicationService;
import com.jeesharp.business.modules.ai.dto.AiFaqSaveDTO;
import com.jeesharp.business.modules.ai.entity.AiFaq;
import com.jeesharp.business.modules.ai.vo.AiFaqInfoVO;
import com.jeesharp.business.modules.ai.vo.AiFaqListVO;
import com.jeesharp.business.modules.ai.vo.AiFaqQueryVO;
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/faq/v1")
@Tag(name = "AI客服-FAQ内容")
@AllArgsConstructor
public class AiFaqController extends BaseController {

    private final AiFaqApplicationService aiFaqApplicationService;

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

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

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

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