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.GameEventProjectVo;
import org.dromara.system.domain.bo.GameEventProjectBo;
import org.dromara.system.service.IGameEventProjectService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 赛事项目
 *
 * @author zlt
 * @date 2025-07-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/gameEventProject")
public class GameEventProjectController extends BaseController {

    private final IGameEventProjectService gameEventProjectService;

    /**
     * 查询赛事项目列表
     */
    @SaCheckPermission("system:gameEventProject:list")
    @GetMapping("/list")
    public TableDataInfo<GameEventProjectVo> list(GameEventProjectBo bo, PageQuery pageQuery) {
        return gameEventProjectService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出赛事项目列表
     */
    @SaCheckPermission("system:gameEventProject:export")
    @Log(title = "赛事项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GameEventProjectBo bo, HttpServletResponse response) {
        List<GameEventProjectVo> list = gameEventProjectService.queryList(bo);
        ExcelUtil.exportExcel(list, "赛事项目", GameEventProjectVo.class, response);
    }

    /**
     * 获取赛事项目详细信息
     *
     * @param projectId 主键
     */
    @SaCheckPermission("system:gameEventProject:query")
    @GetMapping("/{projectId}")
    public R<GameEventProjectVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long projectId) {
        return R.ok(gameEventProjectService.queryById(projectId));
    }

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

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

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