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

import com.jeesharp.business.modules.ai.application.AiFaqCategoryApplicationService;
import com.jeesharp.business.modules.ai.dto.AiFaqCategorySaveDTO;
import com.jeesharp.business.modules.ai.entity.AiFaqCategory;
import com.jeesharp.business.modules.ai.vo.AiFaqCategoryInfoVO;
import com.jeesharp.business.modules.ai.vo.AiFaqCategoryListVO;
import com.jeesharp.business.modules.ai.vo.AiFaqCategoryQueryVO;
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/faqCategory/v1")
@Tag(name = "AI客服-FAQ分类")
@AllArgsConstructor
public class AiFaqCategoryController extends BaseController {

    private final AiFaqCategoryApplicationService aiFaqCategoryApplicationService;

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

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

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

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