package com.kym.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.kym.common.R;
import com.kym.common.annotation.SysLog;
import com.kym.common.controller.IController;
import com.kym.entity.Faq;
import com.kym.entity.queryParams.FaqQueryParam;
import com.kym.service.FaqService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 常见问题 前端控制器
 * </p>
 *
 * @since 2024-11-12
 */
@RestController
@RequestMapping("/faq")
public class FaqController extends IController {

    @Resource
    private FaqService faqService;


    /**
     * 纠错反馈新增接口
     *
     * @param faq 新增纠错反馈
     * @return Res
     */
    @SaCheckPermission(value = "faq.add")
    @PostMapping("add")
    @SysLog(value = "纠错反馈新增接口")
    public R<?> add(@Valid @RequestBody Faq faq) {
//other params checked
        return resp(() -> faqService.add(faq));
    }

    /**
     * 纠错反馈编辑
     *
     * @return Res
     */
    @SaCheckPermission(value = "faq.modify")
    @PostMapping("modify")
    @SysLog(value = "纠错反馈更新接口")
    public R<?> modify(@Valid @RequestBody Faq faq) {
        return resp((t) -> faqService.modify(faq));
    }


    /**
     * 纠错反馈查询接口
     *
     * @return Res
     */
    @SaCheckPermission(value = "faq.list")
    @PostMapping("list")
    @SysLog(value = "纠错反馈列表查询接口")
    public R<?> list(@RequestBody FaqQueryParam query) {
        return resp(() -> faqService.list(query));
    }


    /**
     * 纠错反馈查询详情接口
     *
     * @return Res
     */
    @SaCheckPermission(value = "faq.list")
    @GetMapping("detail/{id}")
    @SysLog(value = "纠错反馈详情查询接口")
    public R<?> detail(@PathVariable long id) {
        return resp(() -> faqService.detail(id));
    }


    /**
     * 纠错反馈变更状态接口
     *
     * @return Res
     */
    @SaCheckPermission(value = "faq.modify")
    @GetMapping("status/{id}/{status}")
    @SysLog(value = "纠错反馈变更状态")
    public R<?> status(@PathVariable long id, @PathVariable int status) {
        return resp((t) -> faqService.status(id, status));
    }


    /**
     * 纠错反馈删除接口
     *
     * @return Res
     */
    @SaCheckPermission(value = "faq.remove")
    @GetMapping("remove/{id}")
    @SysLog(value = "纠错反馈删除")
    public R<?> remove(@PathVariable long id) {
        return resp((t) -> faqService.remove(id));
    }

}
