package com.inkasso.factoring.financingmanagement.web;

import com.inkasso.adapter.response.ResponseData;
import com.inkasso.factoring.acceptanceManagement.entity.CAcceptanceGoodsInfo;
import com.inkasso.factoring.financingmanagement.entity.ContractSignConfirm;
import com.inkasso.factoring.financingmanagement.entity.vo.FinancingApplyVo;
import com.inkasso.factoring.financingmanagement.entity.vo.FinancingSearch;
import com.inkasso.factoring.financingmanagement.entity.vo.GoodsSearch;
import com.inkasso.factoring.financingmanagement.service.FinancingApplyService;
import com.inkasso.factoring.financingmanagement.service.IContractSignConfirmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description : 融资申请Controller
 * @Author : L.Jia
 * @Date: 2023-12-20 10:46
 */

@RestController
@RequestMapping("/financing")
public class FinancingApplyController {

    @Autowired
    private FinancingApplyService financingApplyService;
    @Autowired
    private IContractSignConfirmService contractSignConfirmService;

    /**
     * 我的融资列表页展示
     *
     * @return
     */
    @PostMapping("/list")
    public ResponseData list(@RequestBody FinancingSearch financingSearch) {
        return ResponseData.success(financingApplyService.list(financingSearch));
    }

    /**
     * 选择已验收货物
     *
     * @return
     */
    @PostMapping("/findGoodsByAcceptance")
    public ResponseData findGoodsByAcceptance(@RequestBody GoodsSearch goodsSearch) {
        return ResponseData.success(financingApplyService.findGoodsByAcceptance(goodsSearch));
    }

    /**
     * 生成底层信息
     *
     * @param goodsInfoList 货物信息
     * @return
     */
    @PostMapping("/generateAccountsReceivable")
    public ResponseData generateAccountsReceivable(@RequestBody List<CAcceptanceGoodsInfo> goodsInfoList) {
        return ResponseData.success(financingApplyService.generateAccountsReceivable(goodsInfoList));
    }

    /**
     * 获取联系信息
     *
     * @param businessNumber 业务编号
     * @return
     */
    @GetMapping("/getApplicantInfo")
    public ResponseData getApplicantInfo(String businessNumber) {
        return ResponseData.success(financingApplyService.getApplicantInfo(businessNumber));
    }

    /**
     * 融资申请
     *
     * @return
     */
    @PostMapping("/apply")
    public ResponseData apply(@RequestBody FinancingApplyVo financingApplyVo) {
        financingApplyService.apply(financingApplyVo);
        return ResponseData.success();
    }

    /**
     * 详情页查询
     *
     * @param id
     * @return
     */
    @GetMapping("/getDetail")
    public ResponseData getDetail(Long id) {
        return ResponseData.success(financingApplyService.getDetail(id));
    }

    /**
     * 获取合同签署页面
     *
     * @param id
     * @return
     */
    @GetMapping("/getSignConfirmDetail")
    public ResponseData getSignConfirmDetail(Long id) {
        return ResponseData.success(contractSignConfirmService.getSignConfirmDetail(id));
    }

    /**
     * 刷新认证状态
     *
     * @param sysCustomerId
     * @return
     */
    @GetMapping("/getAuthStatus")
    public ResponseData getAuthStatus(String sysCustomerId) {
        return ResponseData.success(contractSignConfirmService.findAuthInfo(sysCustomerId));
    }

    /**
     * 刷新签署状态
     *
     * @param electronicCustomerInfoId
     * @return
     */
    @GetMapping("/getSignStatus")
    public ResponseData getSignStatus(String electronicCustomerInfoId) {
        return ResponseData.success(contractSignConfirmService.findSignInfo(electronicCustomerInfoId));
    }

    /**
     * 编辑合同签署确认. <br/>
     *
     * @param contractSignConfirm
     * @return
     */
    @PostMapping("/contractSignConfirm/edit")
    public ResponseData edit(@RequestBody ContractSignConfirm contractSignConfirm) {
        return ResponseData.success(contractSignConfirmService.editContractSignConfirm(contractSignConfirm));
    }

    /**
     * 查询sop对应最新收放款计划
     *
     * @param id
     * @return
     */
    @GetMapping("/doViewLatestPlan")
    public ResponseData viewLatestPlan(Long id) {
        return ResponseData.success(financingApplyService.getViewLatestPlan(id));
    }
}
