package com.emoon.knowledge.controller;

import java.util.List;

import com.emoon.common.core.domain.R;
import com.emoon.common.core.validate.validate.AddGroup;
import com.emoon.common.core.validate.validate.EditGroup;
import com.emoon.common.excel.utils.ExcelUtil;
import com.emoon.common.idempotent.annotation.RepeatSubmit;
import com.emoon.common.log.annotation.Log;
import com.emoon.common.log.enums.BusinessType;
import com.emoon.common.mybatis.core.page.PageQuery;
import com.emoon.common.mybatis.core.page.TableDataInfo;
import com.emoon.common.web.core.BaseController;
import com.emoon.knowledge.domain.bo.ThinkAskinfoBo;
import com.emoon.knowledge.domain.vo.ThinkAskinfoVo;
import com.emoon.knowledge.service.IThinkAskinfoService;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;


/**
 * 请求记录
 *
 * @author wangkang
 * @date 2025-11-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/askinfo")
public class ThinkAskinfoController extends BaseController {

    private final IThinkAskinfoService thinkAskinfoService;

    /**
     * 查询请求记录列表
     */
    @SaCheckPermission("system:askinfo:list")
    @GetMapping("/list")
    public TableDataInfo<ThinkAskinfoVo> list(ThinkAskinfoBo bo, PageQuery pageQuery) {
        return thinkAskinfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出请求记录列表
     */
    @SaCheckPermission("system:askinfo:export")
    @Log(title = "请求记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ThinkAskinfoBo bo, HttpServletResponse response) {
        List<ThinkAskinfoVo> list = thinkAskinfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "请求记录", ThinkAskinfoVo.class, response);
    }

    /**
     * 获取请求记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:askinfo:query")
    @GetMapping("/{id}")
    public R<ThinkAskinfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(thinkAskinfoService.queryById(id));
    }

    /**
     * 新增请求记录
     */
    @SaCheckPermission("system:askinfo:add")
    @Log(title = "请求记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ThinkAskinfoBo bo) {
        return toAjax(thinkAskinfoService.insertByBo(bo));
    }

    /**
     * 修改请求记录
     */
    @SaCheckPermission("system:askinfo:edit")
    @Log(title = "请求记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ThinkAskinfoBo bo) {
        return toAjax(thinkAskinfoService.updateByBo(bo));
    }

    /**
     * 删除请求记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:askinfo:remove")
    @Log(title = "请求记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(thinkAskinfoService.deleteWithValidByIds(List.of(ids), true));
    }
}
