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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.contract.BpmOAContractCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.contract.BpmOAContractRespVO;
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOAContractConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAContractDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAContractService;
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;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

/**
 * OA 合同审批 Controller
 *
 * @author 符溶馨

 */
@Tag(name = "管理后台 - OA 合同审批")
@RestController
@RequestMapping("/bpm/oa/contract")
@Validated
public class BpmOAContractController {

    @Resource
    private BpmOAContractService contractService;

    @PostMapping("/create")
    @Operation(summary = "创建请求申请")
    public CommonResult<Long> createContract(@Valid @RequestBody BpmOAContractCreateReqVO createReqVO) {
        return success(contractService.createContract(getLoginUserId(), createReqVO));
    }

    @GetMapping("/get")
    @Operation(summary = "获得合同审批")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BpmOAContractRespVO> getContract(@RequestParam("id") Long id) {

        BpmOAContractDO contract = contractService.getContract(id);

        return success(BpmOAContractConvert.INSTANCE.convert(contract));
    }
}
