package cn.iocoder.yudao.module.bpm.controller.admin.oa;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.procure.BpmOAProcurePageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.procure.BpmOAProcureRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.procurepay.BpmOAProcurePayPageReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.procurepay.BpmOAProcurePayRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.procurepay.BpmOAProcurePaySaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAProcureDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAProcurePayDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAProcurePayService;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAProcureService;
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("/bpm/OA-procure-pay")
@Validated
public class BpmOAProcurePayController {

    @Resource
    private BpmOAProcurePayService oAProcurePayService;
    @Resource
    private BpmOAProcureService oaProcureService;

    @PostMapping("/create")
    @Operation(summary = "创建采购支付")
//    @PreAuthorize("@ss.hasPermission('bpm:OA-procure-pay:create')")
    public CommonResult<Long> createOAProcurePay(@Valid @RequestBody BpmOAProcurePaySaveReqVO createReqVO) {
        return success(oAProcurePayService.createOAProcurePay(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新采购支付")
//    @PreAuthorize("@ss.hasPermission('bpm:OA-procure-pay:update')")
    public CommonResult<Boolean> updateOAProcurePay(@Valid @RequestBody BpmOAProcurePaySaveReqVO updateReqVO) {
        oAProcurePayService.updateOAProcurePay(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除采购支付")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('bpm:OA-procure-pay:delete')")
    public CommonResult<Boolean> deleteOAProcurePay(@RequestParam("id") Long id) {
        oAProcurePayService.deleteOAProcurePay(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得采购支付")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('bpm:OA-procure-pay:query')")
    public CommonResult<BpmOAProcurePayRespVO> getOAProcurePay(@RequestParam("id") Long id) {
        BpmOAProcurePayDO oAProcurePay = oAProcurePayService.getOAProcurePay(id);
        return success(BeanUtils.toBean(oAProcurePay, BpmOAProcurePayRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得采购支付分页")
//    @PreAuthorize("@ss.hasPermission('bpm:OA-procure-pay:query')")
    public CommonResult<PageResult<BpmOAProcurePayRespVO>> getOAProcurePayPage(@Valid BpmOAProcurePayPageReqVO pageReqVO) {
        PageResult<BpmOAProcurePayDO> pageResult = oAProcurePayService.getOAProcurePayPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, BpmOAProcurePayRespVO.class));
    }


    @GetMapping("/getAvailablePurchaseOrders")
    @Operation(summary = "获取可用采购单列表")
    public CommonResult<List<BpmOAProcureRespVO>> getAvailablePurchaseOrders() {
        List<BpmOAProcureDO> list = oAProcurePayService.getAvailablePurchaseOrders();
        return success(BeanUtils.toBean(list, BpmOAProcureRespVO.class));
    }


}