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

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.CueProductDTO;
import com.tmerclub.cloud.cuerecycle.model.vo.CueProductVO;
import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.cuerecycle.service.CueProductService;
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("adminCueProductController")
@RequestMapping("/admin/cueProduct")
public class CueProductController {
    @Resource
    CueProductService cueProductService;

    /**
     * 分页查询
     *
     * @param pageDTO         分页参数
     * @param cueProductDTO 查询参数
     * @return 分页数据
     */
    @GetMapping("/page")
    @Operation(summary = "查询球杆商品分页列表", description = "查询球杆商品分页列表")
    public ServerResponseEntity<PageVO<CueProductVO>> page(@Valid PageDTO pageDTO, CueProductDTO cueProductDTO) {
        PageVO<CueProductVO> cueProductPage = cueProductService.page(pageDTO, cueProductDTO);
        return ServerResponseEntity.success(cueProductPage);
    }


    /**
     * 根据主键id获取球杆商品
     *
     * @param productId 主键id
     * @return CueProductVO
     */
    @GetMapping
    @Operation(summary = "根据id获取球杆商品", description = "根据id获取球杆商品")
    public ServerResponseEntity<CueProductVO> getById(@RequestParam Long productId) {
        CueProductVO cueProduct = cueProductService.getById(productId);
        return ServerResponseEntity.success(cueProduct);
    }

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

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

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