package cn.iocoder.yudao.module.flow.controller.admin.outboundgoods;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.flow.controller.admin.outboundgoods.vo.OutboundGoodsCreateReqVO;
import cn.iocoder.yudao.module.flow.controller.admin.outboundgoods.vo.OutboundGoodsUpdateReqVO;
import cn.iocoder.yudao.module.flow.service.outboundgoods.OutboundGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
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 static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 - 出库单商品")
@RestController
@RequestMapping("/flow/outbound-goods")
@Validated
public class OutboundGoodsController {

    @Resource
    private OutboundGoodsService outboundGoodsService;

    @PostMapping("/create")
    @ApiOperation("创建出库单商品")
    @PreAuthorize("@ss.hasPermission('flow:outbound-goods:create')")
    public CommonResult<Long> createOutboundGoods(@Valid @RequestBody OutboundGoodsCreateReqVO createReqVO) {
        return success(outboundGoodsService.createOutboundGoods(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新出库单商品")
    @PreAuthorize("@ss.hasPermission('flow:outbound-goods:update')")
    public CommonResult<Boolean> updateOutboundGoods(@Valid @RequestBody OutboundGoodsUpdateReqVO updateReqVO) {
        outboundGoodsService.updateOutboundGoods(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除出库单商品")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('flow:outbound-goods:delete')")
    public CommonResult<Boolean> deleteOutboundGoods(@RequestParam("id") Long id) {
        outboundGoodsService.deleteOutboundGoods(id);
        return success(true);
    }
}
