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.InfoPriceResourcePricePageReqVO;
import com.yhy.module.core.controller.admin.infoprice.vo.InfoPriceResourcePriceRespVO;
import com.yhy.module.core.controller.admin.infoprice.vo.InfoPriceResourcePriceSaveReqVO;
import com.yhy.module.core.service.infoprice.InfoPriceResourcePriceService;
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-price")
@Validated
public class InfoPriceResourcePriceController {

    @Resource
    private InfoPriceResourcePriceService resourcePriceService;

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

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

    @DeleteMapping("/delete")
    @Operation(summary = "删除信息价工料机价格历史")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('core:info-price:delete')")
    public CommonResult<Boolean> deleteResourcePrice(@RequestParam("id") Long id) {
        resourcePriceService.deleteResourcePrice(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<InfoPriceResourcePriceRespVO> getResourcePrice(@RequestParam("id") Long id) {
        InfoPriceResourcePriceRespVO resourcePrice = resourcePriceService.getResourcePrice(id);
        return success(resourcePrice);
    }

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

    @GetMapping("/list")
    @Operation(summary = "获得信息价工料机价格历史列表")
    @Parameter(name = "resourceId", description = "工料机信息ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('core:info-price:query')")
    public CommonResult<List<InfoPriceResourcePriceRespVO>> getResourcePriceList(@RequestParam("resourceId") Long resourceId) {
        List<InfoPriceResourcePriceRespVO> list = resourcePriceService.getResourcePriceList(resourceId);
        return success(list);
    }

}
