package com.tmerclub.cloud.cuerecycle.controller.admin;

import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.validate.AddGroup;
import com.tmerclub.cloud.common.validate.EditGroup;
import com.tmerclub.cloud.cuerecycle.model.dto.CueSeriesDTO;
import com.tmerclub.cloud.cuerecycle.model.vo.CueSeriesVO;
import com.tmerclub.cloud.cuerecycle.service.CueSeriesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 球杆系列
 *
 * @author : frank
 * @create : 2025-04-11
 */
@Tag(name = "后管-球杆系列")
@RestController("adminCueSeriesController")
@RequestMapping("/admin/cueSeries")
public class CueSeriesController {
    @Resource
    CueSeriesService cueSeriesService;

    /**
     * 分页查询
     *
     * @param pageDTO      分页参数
     * @param cueSeriesDTO 查询参数
     * @return 分页数据
     */
    @GetMapping("/page")
    @Operation(summary = "查询球杆系列分页列表", description = "查询球杆系列分页列表")
    public ServerResponseEntity<PageVO<CueSeriesVO>> page(@Valid PageDTO pageDTO, CueSeriesDTO cueSeriesDTO) {
        PageVO<CueSeriesVO> cueSeriesPage = cueSeriesService.page(pageDTO, cueSeriesDTO);
        return ServerResponseEntity.success(cueSeriesPage);
    }


    /**
     * 根据主键id获取球杆系列
     *
     * @param seriesId 主键id
     * @return CueSeriesVO
     */
    @GetMapping
    @Operation(summary = "根据id获取球杆系列", description = "根据id获取球杆系列")
    public ServerResponseEntity<CueSeriesVO> getById(@RequestParam Long seriesId) {
        CueSeriesVO cueSeries = cueSeriesService.getById(seriesId);
        return ServerResponseEntity.success(cueSeries);
    }

    /**
     * 新增球杆系列
     *
     * @param cueSeriesDTO CueSeriesDTO
     * @return ServerResponseEntity
     */
    @PostMapping
    @Operation(summary = "新增球杆系列", description = "新增球杆系列")
    public ServerResponseEntity<Void> save(@Validated(AddGroup.class) @RequestBody CueSeriesDTO cueSeriesDTO) {
        int insert = cueSeriesService.save(cueSeriesDTO);
        return insert > 0 ? ServerResponseEntity.success() : ServerResponseEntity.showFailMsg("保存失败");
    }

    /**
     * 修改球杆系列
     *
     * @param cueSeriesDTO CueSeriesDTO
     * @return ServerResponseEntity
     */
    @PutMapping
    @Operation(summary = "修改球杆系列", description = "修改球杆系列")
    public ServerResponseEntity<Void> update(@Validated(EditGroup.class) @RequestBody CueSeriesDTO cueSeriesDTO) {
        int update = cueSeriesService.update(cueSeriesDTO);
        return update > 0 ? ServerResponseEntity.success() : ServerResponseEntity.showFailMsg("修改失败");
    }

    /**
     * 删除球杆系列
     *
     * @param seriesId 主键id
     * @return ServerResponseEntity
     */
    @DeleteMapping
    @Operation(summary = "删除球杆系列", description = "删除球杆系列")
    public ServerResponseEntity<Void> delete(@RequestParam Long seriesId) {
        int delete = cueSeriesService.delete(seriesId);
        return delete > 0 ? ServerResponseEntity.success() : ServerResponseEntity.showFailMsg("删除失败");
    }
}