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.GameRefereeVo;
import org.dromara.system.domain.bo.GameRefereeBo;
import org.dromara.system.service.IGameRefereeService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 裁判
 *
 * @author zlt
 * @date 2025-07-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/gameReferee")
public class GameRefereeController extends BaseController {

    private final IGameRefereeService gameRefereeService;

    /**
     * 查询裁判列表
     */
    @SaCheckPermission("system:gameReferee:list")
    @GetMapping("/list")
    public TableDataInfo<GameRefereeVo> list(GameRefereeBo bo, PageQuery pageQuery) {
        return gameRefereeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出裁判列表
     */
    @SaCheckPermission("system:gameReferee:export")
    @Log(title = "裁判", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GameRefereeBo bo, HttpServletResponse response) {
        List<GameRefereeVo> list = gameRefereeService.queryList(bo);
        ExcelUtil.exportExcel(list, "裁判", GameRefereeVo.class, response);
    }

    /**
     * 获取裁判详细信息
     *
     * @param refereeId 主键
     */
    @SaCheckPermission("system:gameReferee:query")
    @GetMapping("/{refereeId}")
    public R<GameRefereeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long refereeId) {
        return R.ok(gameRefereeService.queryById(refereeId));
    }

    /**
     * 新增裁判
     */
    @SaCheckPermission("system:gameReferee:add")
    @Log(title = "裁判", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody GameRefereeBo bo) {
        return toAjax(gameRefereeService.insertByBo(bo));
    }

    /**
     * 修改裁判
     */
    @SaCheckPermission("system:gameReferee:edit")
    @Log(title = "裁判", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody GameRefereeBo bo) {
        return toAjax(gameRefereeService.updateByBo(bo));
    }

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