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.GameEventConfigTypeVo;
import org.dromara.system.domain.bo.GameEventConfigTypeBo;
import org.dromara.system.service.IGameEventConfigTypeService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

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

    private final IGameEventConfigTypeService gameEventConfigTypeService;

    /**
     * 查询赛事配置类型列表
     */
    @SaCheckPermission("system:gameEventConfigType:list")
    @GetMapping("/list")
    public TableDataInfo<GameEventConfigTypeVo> list(GameEventConfigTypeBo bo, PageQuery pageQuery) {
        return gameEventConfigTypeService.queryPageList(bo, pageQuery);
    }

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

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

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

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

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