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.cuerecycle.model.dto.CueFlawDTO;
import com.tmerclub.cloud.cuerecycle.model.vo.CueFlawVO;
import com.tmerclub.cloud.cuerecycle.service.CueFlawService;
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.web.bind.annotation.*;

/**
 * 球杆缺陷
 *
 * @author : frank
 * @create : 2025-04-13
 */
@Tag(name = "后管-球杆缺陷")
@RestController("adminCueFlawController")
@RequestMapping("/admin/cueFlaw")
public class CueFlawController {
    @Resource
    CueFlawService cueFlawService;

    /**
     * 分页查询
     *
     * @param pageDTO    分页参数
     * @param cueFlawDTO 查询参数
     * @return 分页数据
     */
    @GetMapping("/page")
    @Operation(summary = "查询球杆缺陷分页列表", description = "查询球杆缺陷分页列表")
    public ServerResponseEntity<PageVO<CueFlawVO>> page(@Valid PageDTO pageDTO, CueFlawDTO cueFlawDTO) {
        PageVO<CueFlawVO> cueFlawPage = cueFlawService.page(pageDTO, cueFlawDTO);
        return ServerResponseEntity.success(cueFlawPage);
    }


    /**
     * 根据主键id获取球杆缺陷
     *
     * @param flawId 主键id
     * @return CueFlawVO
     */
    @GetMapping
    @Operation(summary = "根据id获取球杆缺陷", description = "根据id获取球杆缺陷")
    public ServerResponseEntity<CueFlawVO> getById(@RequestParam Long flawId) {
        CueFlawVO cueFlaw = cueFlawService.getById(flawId);
        return ServerResponseEntity.success(cueFlaw);
    }

    /**
     * 新增球杆缺陷
     *
     * @param cueFlawDTO CueFlawDTO
     * @return ServerResponseEntity
     */
    @PostMapping
    @Operation(summary = "新增球杆缺陷", description = "新增球杆缺陷")
    public ServerResponseEntity<Void> save(@Valid @RequestBody CueFlawDTO cueFlawDTO) {
        int insert = cueFlawService.save(cueFlawDTO);
        return insert > 0 ? ServerResponseEntity.success() : ServerResponseEntity.showFailMsg("保存失败");
    }

    /**
     * 修改球杆缺陷
     *
     * @param cueFlawDTO CueFlawDTO
     * @return ServerResponseEntity
     */
    @PutMapping
    @Operation(summary = "修改球杆缺陷", description = "修改球杆缺陷")
    public ServerResponseEntity<Void> update(@Valid @RequestBody CueFlawDTO cueFlawDTO) {
        int update = cueFlawService.update(cueFlawDTO);
        return update > 0 ? ServerResponseEntity.success() : ServerResponseEntity.showFailMsg("修改失败");
    }

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