package org.jk.rag.controller;

import java.util.List;

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

/**
 * 服务器基础信息-静态数据
 *
 * @author Lion Li
 * @date 2026-01-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/baseInfo")
public class ServerBaseInfoController extends BaseController {

    private final IServerBaseInfoService serverBaseInfoService;

    /**
     * 查询服务器基础信息-静态数据列表
     */
    //@SaCheckPermission("system:baseInfo:list")
    @GetMapping("/list")
    public TableDataInfo<ServerBaseInfoVo> list(ServerBaseInfoBo bo, PageQuery pageQuery) {
        return serverBaseInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出服务器基础信息-静态数据列表
     */
    //@SaCheckPermission("system:baseInfo:export")
    @Log(title = "服务器基础信息-静态数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ServerBaseInfoBo bo, HttpServletResponse response) {
        List<ServerBaseInfoVo> list = serverBaseInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务器基础信息-静态数据", ServerBaseInfoVo.class, response);
    }

    /**
     * 获取服务器基础信息-静态数据详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("system:baseInfo:query")
    @GetMapping("/{id}")
    public R<ServerBaseInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(serverBaseInfoService.queryById(id));
    }

    /**
     * 新增服务器基础信息-静态数据
     */
    //@SaCheckPermission("system:baseInfo:add")
    @Log(title = "服务器基础信息-静态数据", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ServerBaseInfoBo bo) {
        return toAjax(serverBaseInfoService.insertByBo(bo));
    }

    /**
     * 修改服务器基础信息-静态数据
     */
    //@SaCheckPermission("system:baseInfo:edit")
    @Log(title = "服务器基础信息-静态数据", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ServerBaseInfoBo bo) {
        return toAjax(serverBaseInfoService.updateByBo(bo));
    }

    /**
     * 删除服务器基础信息-静态数据
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("system:baseInfo:remove")
    @Log(title = "服务器基础信息-静态数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(serverBaseInfoService.deleteWithValidByIds(List.of(ids), true));
    }
}
