package com.sunxung.factoring.web.salescontractmanagement;

import com.sunxung.factoring.component.annotation.OperationLog;
import com.sunxung.factoring.component.enums.OperationTypeEnum;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.salescontractmanagement.CSalesContractSupplementBasicInfo;
import com.sunxung.factoring.entity.salescontractmanagement.CSalesContractSupplementInfo;
import com.sunxung.factoring.entity.salescontractmanagement.CSalesSupplementSignConfirmation;
import com.sunxung.factoring.entity.salescontractmanagement.CSalesSupplementSignConfirmationElectronicInfo;
import com.sunxung.factoring.service.salescontractmanagement.ICSalesContractSupplementBasicInfoService;
import com.sunxung.factoring.service.salescontractmanagement.ICSalesSupplementSignConfirmationElectronicInfoService;
import com.sunxung.factoring.service.salescontractmanagement.ICSalesSupplementSignConfirmationService;
import com.sunxung.factoring.service.salescontractmanagement.ISalesContractSupplementInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 销售合同变更对外接口
 * @Author Yafan Wang
 * @Date 2024/1/7 10:55
 */
@RestController
@RequestMapping("/api/salesManagement/change")
public class SalesContractChangeApiController {


    @Autowired
    private ISalesContractSupplementInfoService salesContractSupplementInfoService;
    @Autowired
    private ICSalesContractSupplementBasicInfoService salesContractSupplementBasicInfoService;
    @Autowired
    private ICSalesSupplementSignConfirmationService salesSupplementSignConfirmationService;
    @Autowired
    private ICSalesSupplementSignConfirmationElectronicInfoService salesSupplementSignConfirmationElectronicInfoService;


    /**
     * 销售合同变更创建保存
     *
     * @return
     */
    @PostMapping("/doChange")
    @OperationLog(operationModule = "销售合同变更", operationType = OperationTypeEnum.INSERT, description = "销售合同变更创建保存")
    public Object doChange(@RequestBody CSalesContractSupplementInfo salesContractSupplementInfo) {
        salesContractSupplementInfoService.doChange(salesContractSupplementInfo);
        return new ResponseJson("提交成功");
    }


    /**
     * 销售合同变更录入保存
     *
     * @return
     */
    @PostMapping("/doEnter")
    @OperationLog(operationModule = "销售合同变更", operationType = OperationTypeEnum.INSERT, description = "销售合同变更创建保存")
    public ResponseJson doEnter(@RequestBody CSalesContractSupplementBasicInfo basicInfo){
        salesContractSupplementBasicInfoService.doAdd(basicInfo);
        return new ResponseJson("操作成功！");
    }

    /**
     * 上传合同
     * @param salesSupplementSignConfirmation
     * @return
     */
    @PostMapping("/uploadContract")
    public ResponseJson uploadContract(@RequestBody CSalesSupplementSignConfirmation salesSupplementSignConfirmation){
        return new ResponseJson(salesSupplementSignConfirmationService.uploadContract(salesSupplementSignConfirmation));
    }

    /**
     * 签署回调
     * @param supplementSignConfirmationElectronicInfo
     */
    @PostMapping("/signBack")
    public void signBack(@RequestBody CSalesSupplementSignConfirmationElectronicInfo supplementSignConfirmationElectronicInfo){
        salesSupplementSignConfirmationElectronicInfoService.doSignCallBack(supplementSignConfirmationElectronicInfo);
    }

    /**
     * 签署确认提交
     * @param salesSupplementSignConfirmation
     * @return
     */
    @PostMapping("/doSign")
    public ResponseJson doSign(@RequestBody CSalesSupplementSignConfirmation salesSupplementSignConfirmation){
        salesSupplementSignConfirmationService.doAdd(salesSupplementSignConfirmation);
        return new ResponseJson("操作成功！");
    }

    @GetMapping("/view")
    public ResponseJson getView(@RequestParam Long id){
        return new ResponseJson(salesSupplementSignConfirmationService.getView(id));
    }

}
