package com.yhy.module.core.controller.admin.infoprice;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.yhy.module.core.controller.admin.infoprice.vo.InfoPriceResourcePageReqVO;
import com.yhy.module.core.controller.admin.infoprice.vo.InfoPriceResourceRespVO;
import com.yhy.module.core.controller.admin.infoprice.vo.InfoPriceResourceSaveReqVO;
import com.yhy.module.core.service.infoprice.InfoPriceResourceService;
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.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

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

@Tag(name = "管理后台 - 信息价工料机信息")
@RestController
@RequestMapping("/core/info-price/resource")
@Validated
public class InfoPriceResourceController {

    @Resource
    private InfoPriceResourceService resourceService;

    @PostMapping("/create")
    @Operation(summary = "创建信息价工料机信息")
    @PreAuthorize("@ss.hasPermission('core:info-price:create')")
    public CommonResult<Long> createResource(@Valid @RequestBody InfoPriceResourceSaveReqVO createReqVO) {
        return success(resourceService.createResource(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新信息价工料机信息")
    @PreAuthorize("@ss.hasPermission('core:info-price:update')")
    public CommonResult<Boolean> updateResource(@Valid @RequestBody InfoPriceResourceSaveReqVO updateReqVO) {
        resourceService.updateResource(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除信息价工料机信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('core:info-price:delete')")
    public CommonResult<Boolean> deleteResource(@RequestParam("id") Long id) {
        resourceService.deleteResource(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得信息价工料机信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:info-price:query')")
    public CommonResult<InfoPriceResourceRespVO> getResource(@RequestParam("id") Long id) {
        InfoPriceResourceRespVO resource = resourceService.getResource(id);
        return success(resource);
    }

    @GetMapping("/page")
    @Operation(summary = "获得信息价工料机信息分页")
    @PreAuthorize("@ss.hasPermission('core:info-price:query')")
    public CommonResult<PageResult<InfoPriceResourceRespVO>> getResourcePage(@Valid InfoPriceResourcePageReqVO pageReqVO) {
        PageResult<InfoPriceResourceRespVO> pageResult = resourceService.getResourcePage(pageReqVO);
        return success(pageResult);
    }

    @GetMapping("/list")
    @Operation(summary = "获得信息价工料机信息列表")
    @Parameter(name = "categoryTreeId", description = "分类树节点ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:info-price:query')")
    public CommonResult<List<InfoPriceResourceRespVO>> getResourceList(@RequestParam("categoryTreeId") Long categoryTreeId) {
        List<InfoPriceResourceRespVO> list = resourceService.getResourceList(categoryTreeId);
        return success(list);
    }

}
