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.GameEventGroupVo;
import org.dromara.system.domain.bo.GameEventGroupBo;
import org.dromara.system.service.IGameEventGroupService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 赛事分组
 *
 * @author zlt
 * @date 2025-07-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/gameEventGroup")
public class GameEventGroupController extends BaseController {

    private final IGameEventGroupService gameEventGroupService;

    /**
     * 查询赛事分组列表
     */
    @SaCheckPermission("system:gameEventGroup:list")
    @GetMapping("/list")
    public TableDataInfo<GameEventGroupVo> list(GameEventGroupBo bo, PageQuery pageQuery) {
        return gameEventGroupService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出赛事分组列表
     */
    @SaCheckPermission("system:gameEventGroup:export")
    @Log(title = "赛事分组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GameEventGroupBo bo, HttpServletResponse response) {
        List<GameEventGroupVo> list = gameEventGroupService.queryList(bo);
        ExcelUtil.exportExcel(list, "赛事分组", GameEventGroupVo.class, response);
    }

    /**
     * 获取赛事分组详细信息
     *
     * @param groupId 主键
     */
    @SaCheckPermission("system:gameEventGroup:query")
    @GetMapping("/{groupId}")
    public R<GameEventGroupVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long groupId) {
        return R.ok(gameEventGroupService.queryById(groupId));
    }

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

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

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