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.GameScoreVo;
import org.dromara.system.domain.bo.GameScoreBo;
import org.dromara.system.service.IGameScoreService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 成绩
 *
 * @author zlt
 * @date 2025-07-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/gameScore")
public class GameScoreController extends BaseController {

    private final IGameScoreService gameScoreService;

    /**
     * 查询成绩列表
     */
    @SaCheckPermission("system:gameScore:list")
    @GetMapping("/list")
    public TableDataInfo<GameScoreVo> list(GameScoreBo bo, PageQuery pageQuery) {
        return gameScoreService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出成绩列表
     */
    @SaCheckPermission("system:gameScore:export")
    @Log(title = "成绩", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GameScoreBo bo, HttpServletResponse response) {
        List<GameScoreVo> list = gameScoreService.queryList(bo);
        ExcelUtil.exportExcel(list, "成绩", GameScoreVo.class, response);
    }

    /**
     * 获取成绩详细信息
     *
     * @param scoreId 主键
     */
    @SaCheckPermission("system:gameScore:query")
    @GetMapping("/{scoreId}")
    public R<GameScoreVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long scoreId) {
        return R.ok(gameScoreService.queryById(scoreId));
    }

    /**
     * 新增成绩
     */
    @SaCheckPermission("system:gameScore:add")
    @Log(title = "成绩", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody GameScoreBo bo) {
        return toAjax(gameScoreService.insertByBo(bo));
    }

    /**
     * 修改成绩
     */
    @SaCheckPermission("system:gameScore:edit")
    @Log(title = "成绩", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody GameScoreBo bo) {
        return toAjax(gameScoreService.updateByBo(bo));
    }

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