package top.continew.admin.controller.business;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import top.continew.admin.business.model.query.ScoreQuery;
import top.continew.admin.business.model.req.ScoreAddReq;
import top.continew.admin.business.model.req.ScoreEditReq;
import top.continew.admin.business.model.resp.ScoreResp;
import top.continew.admin.business.service.ScoreService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.web.model.R;
import java.util.List;

/**
 * 分数管理 API
 *
 * @author jiay
 * @since 2025/06/26 10:24
 */
@Tag(name = "分数 API")
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/score")
public class ScoreController {
    private final ScoreService scoreService;

    @Operation(summary = "添加分数", description = "添加分数")
    @PostMapping("/add")
    public R<Void> add(@RequestBody @Valid ScoreAddReq req) {
        return R.ok(scoreService.addScore(req));
    }

    @Operation(summary = "编辑分数", description = "编辑分数")
    @PostMapping("/edit")
    public R<Void> edit(@RequestBody @Valid ScoreEditReq req) {
        return scoreService.editScore(req) ? R.ok() : R.fail();
    }

    @Operation(summary = "删除分数", description = "删除分数")
    @DeleteMapping("/delete")
    public R<Void> delete(@RequestParam Long id) {
        return scoreService.deleteScore(id) ? R.ok() : R.fail();
    }

    @Operation(summary = "获取分数", description = "获取分数")
    @GetMapping("/get")
    public R<ScoreResp> getScore(@RequestParam(name = "id", required = true) Long id) {
        return R.ok(scoreService.getScore(id));
    }

    @Operation(summary = "查询分数列表", description = "查询分数列表")
    @GetMapping("/list")
    public R<List<ScoreResp>> getScoreList(ScoreQuery query) {
        return R.ok(scoreService.getScoreList(query));
    }

    @Operation(summary = "分页查询分数列表", description = "分页查询分数列表")
    @GetMapping
    public R<PageResp<ScoreResp>> page(ScoreQuery query, @Validated PageQuery pageQuery) {
        return R.ok(scoreService.getScorePage(query, pageQuery));
    }
}