package cn.iocoder.yudao.module.project.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.project.entity.RepairWares;
import cn.iocoder.yudao.module.project.service.RepairWaresService;
import cn.iocoder.yudao.module.project.vo.RepairWaresPageReqVO;
import cn.iocoder.yudao.module.project.vo.RepairWaresRespVO;
import cn.iocoder.yudao.module.project.vo.RepairWaresSaveReqVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 配件库")
@RestController
@RequestMapping("/repair/wares")
@Validated
public class RepairWaresController {

    @Resource
    private RepairWaresService waresService;

    /**
     * 创建配件库
     *
     * @param createReqVO RepairWaresSaveReqVO实体
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.String>
     * @author PQZ
     * @date 11:20 2024/9/14
     **/
    @PostMapping("/create")
    @Operation(summary = "创建配件库")
//    @PreAuthorize("@ss.hasPermission('repair:wares:create')")
    public CommonResult<RepairWares> createWares(@Valid @RequestBody RepairWaresSaveReqVO createReqVO) {
        return success(waresService.saveWares(createReqVO));
    }

    /**
     * 更新配件库
     *
     * @param updateReqVO RepairWaresSaveReqVO实体
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 11:21 2024/9/14
     **/
    @PutMapping("/update")
    @Operation(summary = "更新配件库")
//    @PreAuthorize("@ss.hasPermission('repair:wares:update')")
    public CommonResult<Boolean> updateWares(@Valid @RequestBody RepairWaresSaveReqVO updateReqVO) {
        waresService.saveWares(updateReqVO);
        return success(true);
    }

    /**
     * 删除配件库
     *
     * @param id 产品id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.lang.Boolean>
     * @author PQZ
     * @date 11:21 2024/9/14
     **/
    @DeleteMapping("/delete")
    @Operation(summary = "删除配件库")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('repair:wares:delete')")
    public CommonResult<Boolean> deleteWares(@RequestParam("id") String id) {
        waresService.deleteWares(id);
        return success(true);
    }

    /**
     * 获得配件库
     *
     * @param id 产品id
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.module.project.vo.RepairWaresRespVO>
     * @author PQZ
     * @date 11:21 2024/9/14
     **/
    @GetMapping("/get")
    @Operation(summary = "获得配件库")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('repair:wares:query')")
    public CommonResult<RepairWaresRespVO> getWares(@RequestParam("id") String id) {
        return success(waresService.getWares(id));
    }

    /**
     * 获得配件库分页
     *
     * @param pageReqVO RepairWaresPageReqVO 实体
     * @param pageNo    分页参数
     * @param pageSize  分页参数
     * @return cn.iocoder.yudao.framework.common.pojo.CommonResult<com.baomidou.mybatisplus.core.metadata.IPage < ?>>
     * @author PQZ
     * @date 11:30 2024/9/14
     **/
    @GetMapping("/page")
    @Operation(summary = "获得配件库分页")
//    @PreAuthorize("@ss.hasPermission('repair:wares:query')")
    public CommonResult<IPage<?>> getWaresPage(RepairWaresPageReqVO pageReqVO,
                                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<RepairWaresRespVO> page = new Page<>(pageNo, pageSize);
        return success(waresService.getWaresPage(pageReqVO, page));
    }

    /**
     * 根据名称获取最新的数据
     *
     * @author 小李
     * @date 18:03 2024/9/25
    **/
    @GetMapping("/getByName")
    @Operation(summary = "根据名称获取最新的数据")
    public CommonResult<?> getWaresByName(@RequestParam("name") String name) {
        return success(waresService.getWaresByName(name));
    }

    /**
     * 查询所有有配件的分类
     * @author vinjor-M
     * @date 10:51 2024/10/22
    **/
    @GetMapping("/getAllTypeList")
    @Operation(summary = "查询所有有配件的分类")
    public CommonResult<?> getAllTypeList() {
        return success(waresService.getAllTypeList());
    }

}