package org.dromara.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.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.domain.vo.SenAlgorithmConfigVo;
import org.dromara.domain.bo.SenAlgorithmConfigBo;
import org.dromara.service.ISenAlgorithmConfigService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 算法仓配置
 *
 * @author luogang
 * @date 2024-09-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/manage/algorithmConfig")
public class SenAlgorithmConfigController extends BaseController {

    private final ISenAlgorithmConfigService senAlgorithmConfigService;

    /**
     * 查询算法仓配置列表
     */
    @SaCheckPermission("manage:algorithmConfig:list")
    @GetMapping("/list")
    public TableDataInfo<SenAlgorithmConfigVo> list(SenAlgorithmConfigBo bo, PageQuery pageQuery) {
        return senAlgorithmConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出算法仓配置列表
     */
    @SaCheckPermission("manage:algorithmConfig:export")
    @Log(title = "算法仓配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SenAlgorithmConfigBo bo, HttpServletResponse response) {
        List<SenAlgorithmConfigVo> list = senAlgorithmConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "算法仓配置", SenAlgorithmConfigVo.class, response);
    }

    /**
     * 获取算法仓配置详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("manage:algorithmConfig:query")
    @GetMapping("/{id}")
    public R<SenAlgorithmConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(senAlgorithmConfigService.queryById(id));
    }

    /**
     * 新增算法仓配置
     */
    @SaCheckPermission("manage:algorithmConfig:add")
    @Log(title = "算法仓配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SenAlgorithmConfigBo bo) {
        return toAjax(senAlgorithmConfigService.insertByBo(bo));
    }

    /**
     * 修改算法仓配置
     */
    @SaCheckPermission("manage:algorithmConfig:edit")
    @Log(title = "算法仓配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SenAlgorithmConfigBo bo) {
        return toAjax(senAlgorithmConfigService.updateByBo(bo));
    }

    /**
     * 删除算法仓配置
     *
     * @param ids 主键串
     */
    @SaCheckPermission("manage:algorithmConfig:remove")
    @Log(title = "算法仓配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(senAlgorithmConfigService.deleteWithValidByIds(List.of(ids), true));
    }
}
