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.GameEventVo;
import org.dromara.system.domain.bo.GameEventBo;
import org.dromara.system.service.IGameEventService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 赛事基本信息
 *
 * @author zlt
 * @date 2025-07-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/gameEvent")
public class GameEventController extends BaseController {

    private final IGameEventService gameEventService;

    /**
     * 查询赛事基本信息列表
     */
    @SaCheckPermission("system:gameEvent:list")
    @GetMapping("/list")
    public TableDataInfo<GameEventVo> list(GameEventBo bo, PageQuery pageQuery) {
        return gameEventService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出赛事基本信息列表
     */
    @SaCheckPermission("system:gameEvent:export")
    @Log(title = "赛事基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GameEventBo bo, HttpServletResponse response) {
        List<GameEventVo> list = gameEventService.queryList(bo);
        ExcelUtil.exportExcel(list, "赛事基本信息", GameEventVo.class, response);
    }

    /**
     * 获取赛事基本信息详细信息
     *
     * @param eventId 主键
     */
    @SaCheckPermission("system:gameEvent:query")
    @GetMapping("/{eventId}")
    public R<GameEventVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long eventId) {
        return R.ok(gameEventService.queryById(eventId));
    }

    /**
     * 新增赛事基本信息
     */
    @SaCheckPermission("system:gameEvent:add")
    @Log(title = "赛事基本信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody GameEventBo bo) {
        return toAjax(gameEventService.insertByBo(bo));
    }

    /**
     * 修改赛事基本信息
     */
    @SaCheckPermission("system:gameEvent:edit")
    @Log(title = "赛事基本信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody GameEventBo bo) {
        return toAjax(gameEventService.updateByBo(bo));
    }

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