package org.dromara.system.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.system.domain.vo.GameEventConfigVo;
import org.dromara.system.domain.bo.GameEventConfigBo;
import org.dromara.system.service.IGameEventConfigService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 赛事配置
 *
 * @author zlt
 * @date 2025-07-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/gameEventConfig")
public class GameEventConfigController extends BaseController {

    private final IGameEventConfigService gameEventConfigService;

    /**
     * 查询赛事配置列表
     */
    @SaCheckPermission("system:gameEventConfig:list")
    @GetMapping("/list")
    public TableDataInfo<GameEventConfigVo> list(GameEventConfigBo bo, PageQuery pageQuery) {
        return gameEventConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出赛事配置列表
     */
    @SaCheckPermission("system:gameEventConfig:export")
    @Log(title = "赛事配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GameEventConfigBo bo, HttpServletResponse response) {
        List<GameEventConfigVo> list = gameEventConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "赛事配置", GameEventConfigVo.class, response);
    }

    /**
     * 获取赛事配置详细信息
     *
     * @param configId 主键
     */
    @SaCheckPermission("system:gameEventConfig:query")
    @GetMapping("/{configId}")
    public R<GameEventConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long configId) {
        return R.ok(gameEventConfigService.queryById(configId));
    }

    /**
     * 新增赛事配置
     */
    @SaCheckPermission("system:gameEventConfig:add")
    @Log(title = "赛事配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody GameEventConfigBo bo) {
        return toAjax(gameEventConfigService.insertByBo(bo));
    }

    /**
     * 修改赛事配置
     */
    @SaCheckPermission("system:gameEventConfig:edit")
    @Log(title = "赛事配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody GameEventConfigBo bo) {
        return toAjax(gameEventConfigService.updateByBo(bo));
    }

    /**
     * 删除赛事配置
     *
     * @param configIds 主键串
     */
    @SaCheckPermission("system:gameEventConfig:remove")
    @Log(title = "赛事配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{configIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] configIds) {
        return toAjax(gameEventConfigService.deleteWithValidByIds(List.of(configIds), true));
    }
}
