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.ThinkMcpBo;
import com.emoon.knowledge.domain.vo.ThinkMcpVo;
import com.emoon.knowledge.service.IThinkMcpService;
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/mcp")
public class ThinkMcpController extends BaseController {

    private final IThinkMcpService thinkMcpService;

    /**
     * 查询【请填写功能名称】列表
     */
    @SaCheckPermission("system:mcp:list")
    @GetMapping("/list")
    public TableDataInfo<ThinkMcpVo> list(ThinkMcpBo bo, PageQuery pageQuery) {
        return thinkMcpService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @SaCheckPermission("system:mcp:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ThinkMcpBo bo, HttpServletResponse response) {
        List<ThinkMcpVo> list = thinkMcpService.queryList(bo);
        ExcelUtil.exportExcel(list, "【请填写功能名称】", ThinkMcpVo.class, response);
    }

    /**
     * 获取【请填写功能名称】详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:mcp:query")
    @GetMapping("/{id}")
    public R<ThinkMcpVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(thinkMcpService.queryById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @SaCheckPermission("system:mcp:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ThinkMcpBo bo) {
        return toAjax(thinkMcpService.insertByBo(bo));
    }

    /**
     * 修改【请填写功能名称】
     */
    @SaCheckPermission("system:mcp:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ThinkMcpBo bo) {
        return toAjax(thinkMcpService.updateByBo(bo));
    }

    /**
     * 删除【请填写功能名称】
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:mcp:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(thinkMcpService.deleteWithValidByIds(List.of(ids), true));
    }
}
