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.CueBrandDTO;
import com.tmerclub.cloud.cuerecycle.model.vo.CueBrandVO;
import com.tmerclub.cloud.cuerecycle.service.CueBrandService;
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("adminCueBrandController")
@RequestMapping("/admin/cueBrand")
public class CueBrandController {
    @Resource
    CueBrandService cueBrandService;

    /**
     * 分页查询
     *
     * @param pageDTO     分页参数
     * @param cueBrandDTO 查询参数
     * @return 分页数据
     */
    @GetMapping("/page")
    @Operation(summary = "查询球杆品牌分页列表", description = "查询球杆品牌分页列表")
    public ServerResponseEntity<PageVO<CueBrandVO>> page(@Valid PageDTO pageDTO, CueBrandDTO cueBrandDTO) {
        PageVO<CueBrandVO> cueBrandPage = cueBrandService.page(pageDTO, cueBrandDTO);
        return ServerResponseEntity.success(cueBrandPage);
    }


    /**
     * 根据主键id获取球杆品牌
     *
     * @param brandId 主键id
     * @return CueBrandVO
     */
    @GetMapping
    @Operation(summary = "根据id获取球杆品牌", description = "根据id获取球杆品牌")
    public ServerResponseEntity<CueBrandVO> getById(@RequestParam Long brandId) {
        CueBrandVO cueBrand = cueBrandService.getById(brandId);
        return ServerResponseEntity.success(cueBrand);
    }

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

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

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