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.GameTeamVo;
import org.dromara.system.domain.bo.GameTeamBo;
import org.dromara.system.service.IGameTeamService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 参赛队伍
 *
 * @author zlt
 * @date 2025-07-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/gameTeam")
public class GameTeamController extends BaseController {

    private final IGameTeamService gameTeamService;

    /**
     * 查询参赛队伍列表
     */
    @SaCheckPermission("system:gameTeam:list")
    @GetMapping("/list")
    public TableDataInfo<GameTeamVo> list(GameTeamBo bo, PageQuery pageQuery) {
        return gameTeamService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出参赛队伍列表
     */
    @SaCheckPermission("system:gameTeam:export")
    @Log(title = "参赛队伍", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GameTeamBo bo, HttpServletResponse response) {
        List<GameTeamVo> list = gameTeamService.queryList(bo);
        ExcelUtil.exportExcel(list, "参赛队伍", GameTeamVo.class, response);
    }

    /**
     * 获取参赛队伍详细信息
     *
     * @param teamId 主键
     */
    @SaCheckPermission("system:gameTeam:query")
    @GetMapping("/{teamId}")
    public R<GameTeamVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long teamId) {
        return R.ok(gameTeamService.queryById(teamId));
    }

    /**
     * 新增参赛队伍
     */
    @SaCheckPermission("system:gameTeam:add")
    @Log(title = "参赛队伍", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody GameTeamBo bo) {
        return toAjax(gameTeamService.insertByBo(bo));
    }

    /**
     * 修改参赛队伍
     */
    @SaCheckPermission("system:gameTeam:edit")
    @Log(title = "参赛队伍", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody GameTeamBo bo) {
        return toAjax(gameTeamService.updateByBo(bo));
    }

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