package cn.superdesk.uniorder.dubbo.consumer.invoice.customer.state;

import cn.superdesk.uniorder.common.security.JwtUtil;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.invoice.customer.InvoiceApply;
import cn.superdesk.uniorder.dao.entity.sys.notify.SysNotify;
import cn.superdesk.uniorder.dto.param.thirdpart.szhtxx.common.singleBilling.SzhtxxInvoiceFptxxOpSingleBillingForm;
import cn.superdesk.uniorder.dto.param.thirdpart.szhtxx.common.singleSelect.SzhtxxInvoiceFptxxOpSingleSelectForm;
import cn.superdesk.uniorder.dubbo.consumer._permission.PermissionDubboCustomerService;
import cn.superdesk.uniorder.dubbo.facade.invoice.customer.state.DubboInvoiceApplyFieldMakeInvoiceStatusService;
import cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.electronicInvoice.dto.request.SingleBillingRequestBodyKpContent;
import cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.paperInvoice.dto.request.SID17SingleSelect.SID17SingleSelectRequestBody;
import cn.superdesk.uniorder.openapicall.thirdpart.szhtxx.paperInvoice.dto.request.SID1SingleBilling.SID1SingleBillingRequestBody;
import com.alibaba.dubbo.config.annotation.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


/**
 * @Description: 简易状态机 星型结构
 * @Author: linjinyu
 * @CreateDate: 10/12/20 4:28 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 10/12/20 4:28 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Component
public class InvoiceApplyFieldMakeInvoiceStatusDubboConsumerService {

    @Reference(version = "1.0.0", timeout = 300000, retries = -1)
    private DubboInvoiceApplyFieldMakeInvoiceStatusService dubboInvoiceApplyFieldMakeInvoiceStatusService;

    @Resource
    private PermissionDubboCustomerService permissionDubboCustomerService;

    /****************************************** 状态机 外部使用 类门面 start ******************************************/


    // 状态流转为 待开票(0, "待开票")
    public SysNotify opInit(InvoiceApply entity, String token) {
        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
        return dubboInvoiceApplyFieldMakeInvoiceStatusService.opInit(entity, loginSysUser);
    }

    // 状态流转为 已作废(2, "已作废")
    public SysNotify opBecomeInvalid(InvoiceApply entity, String token) {
        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
        return dubboInvoiceApplyFieldMakeInvoiceStatusService.opBecomeInvalid(entity, loginSysUser);
    }


    /**************************************** 电子普通发票-深圳航信电子发票 start ****************************************/


    // 状态流转为 开票中(10, "开票中")
    public SingleBillingRequestBodyKpContent opOngoingInvoiceTypeEq1InvoiceModeEqSzhtxxElectronicInvoice(
            SzhtxxInvoiceFptxxOpSingleBillingForm form,
            InvoiceApply entity,
            String token) {
        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
        return dubboInvoiceApplyFieldMakeInvoiceStatusService.opOngoingInvoiceTypeEq1InvoiceModeEqSzhtxxElectronicInvoice(form, entity, loginSysUser);
    }

    // 状态流转为 开票中(10, "开票中")
    public String exportOngoingInvoiceTypeEq1InvoiceModeEqSzhtxxElectronicInvoice(SzhtxxInvoiceFptxxOpSingleBillingForm form, InvoiceApply entity, String token) {
        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
        return dubboInvoiceApplyFieldMakeInvoiceStatusService.exportOngoingInvoiceTypeEq1InvoiceModeEqSzhtxxElectronicInvoice(form, entity, loginSysUser);
    }

    // 状态流转为 开票中(10, "开票中")
    public SysNotify opOngoing(
            SzhtxxInvoiceFptxxOpSingleBillingForm form,
            InvoiceApply entity,
            String token) {
        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
        return dubboInvoiceApplyFieldMakeInvoiceStatusService.opOngoing(form, entity, loginSysUser);
    }

    /**************************************** 电子普通发票-深圳航信电子发票   end ****************************************/

    /**************************************** 纸质专用发票-深圳航信纸质发票 start ****************************************/

    // 状态流转为 开票中(10, "开票中")
    public SID1SingleBillingRequestBody opOngoingInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoice(
            SzhtxxInvoiceFptxxOpSingleBillingForm form,
            InvoiceApply entity,
            String token) {
        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
        return dubboInvoiceApplyFieldMakeInvoiceStatusService.opOngoingInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoice(form, entity, loginSysUser);
    }


    // 状态流转为 已开票(11, "已开票")
    public SID17SingleSelectRequestBody opCompleteInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoiceRequest(
            SzhtxxInvoiceFptxxOpSingleSelectForm form,
            InvoiceApply entity,
            String token) {
        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
        return dubboInvoiceApplyFieldMakeInvoiceStatusService.opCompleteInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoiceRequest(form, entity, loginSysUser);
    }

    // 状态流转为 已开票(11, "已开票")
    public SysNotify opCompleteInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoiceResponse(
            SzhtxxInvoiceFptxxOpSingleSelectForm form,
            InvoiceApply entity,
            String token) {
        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
        return dubboInvoiceApplyFieldMakeInvoiceStatusService.opCompleteInvoiceTypeEq2InvoiceModeEqSzhtxxPaperInvoiceResponse(form, entity, loginSysUser);
    }

    /**************************************** 纸质专用发票-深圳航信纸质发票   end ****************************************/


    // 状态流转为 已开票(11, "已开票")
    public SysNotify opComplete(InvoiceApply entity, String token) {
        LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
        return dubboInvoiceApplyFieldMakeInvoiceStatusService.opComplete(entity, loginSysUser);
    }

    /****************************************** 状态机 外部使用 类门面   end ******************************************/
}
