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.CueTypeDTO;
import com.tmerclub.cloud.cuerecycle.model.vo.CueTypeVO;
import com.tmerclub.cloud.cuerecycle.service.CueTypeService;
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 21:22:35
 */
@Tag(name = "后管-球杆类型")
@RestController("adminCueTypeController")
@RequestMapping("/admin/cueType")
public class CueTypeController {
    @Resource
    CueTypeService cueTypeService;

    /**
     * 分页查询
     *
     * @param pageDTO    分页参数
     * @param cueTypeDTO 查询参数
     * @return 分页数据
     */
    @GetMapping("/page")
    @Operation(summary = "查询球杆类型分页列表", description = "查询球杆类型分页列表")
    public ServerResponseEntity<PageVO<CueTypeVO>> page(@Valid PageDTO pageDTO, CueTypeDTO cueTypeDTO) {
        PageVO<CueTypeVO> cueTypePage = cueTypeService.page(pageDTO, cueTypeDTO);
        return ServerResponseEntity.success(cueTypePage);
    }


    /**
     * 根据主键id获取球杆类型
     *
     * @param typeId 主键id
     * @return CueTypeVO
     */
    @GetMapping
    @Operation(summary = "根据id获取球杆类型", description = "根据id获取球杆类型")
    public ServerResponseEntity<CueTypeVO> getById(@RequestParam Long typeId) {
        CueTypeVO cueType = cueTypeService.getById(typeId);
        return ServerResponseEntity.success(cueType);
    }

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

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

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