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.imprest.BpmOAImprestCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.imprest.BpmOAImprestRespVO;
import cn.iocoder.yudao.module.bpm.convert.oa.BpmOAImprestConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAImprestDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOAImprestService;
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/imprest")
@Validated
public class BpmOAImprestController {

    @Resource
    private BpmOAImprestService imprestService;

    @PostMapping("/create")
    @Operation(summary = "创建请求申请")
    public CommonResult<Long> createImprest(@Valid @RequestBody BpmOAImprestCreateReqVO createReqVO) {

        return success(imprestService.createImprest(getLoginUserId(), createReqVO));
    }

    @GetMapping("/get")
    @Operation(summary = "获得备用金申请")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BpmOAImprestRespVO> getImprest(@RequestParam("id") Long id) {

        BpmOAImprestDO imprest = imprestService.getImprest(id);

        return success(BpmOAImprestConvert.INSTANCE.convert(imprest));
    }

    @GetMapping("/getOne")
    @Operation(summary = "获得备用金表单")
    @Parameter(name = "userId", description = "编号", required = true, example = "1024")
    public CommonResult<BpmOAImprestRespVO> getImprestByUserId(@RequestParam("userId") Long userId) {

        //根据user 查询审批通过并且未报销得表单。
        BpmOAImprestDO imprest = imprestService.getImprestByUserId(userId);

        return success(BpmOAImprestConvert.INSTANCE.convert(imprest));
    }

    @GetMapping("/getProcessInstanceId")
    @Operation(summary = "获得备用金表单")
    @Parameter(name = "reimbursementId", description = "编号", required = true, example = "1024")
    public CommonResult<BpmOAImprestRespVO> getImprestByReimbursementId(@RequestParam("reimbursementId") Long reimbursementId) {

        //根据user 查询审批通过并且未报销得表单。
        BpmOAImprestDO imprest = imprestService.getImprestByReimbursementId(reimbursementId);

        return success(BpmOAImprestConvert.INSTANCE.convert(imprest));
    }
}
