package cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceApply.makeInvoiceStatus.context;

import cn.superdesk.uniorder.common.enums.invoice.customer.InvoiceApplyCustomerMakeInvoiceStatusEnum;
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.pattern.state.invoice.customer.invoiceApply.makeInvoiceStatus.state.InvoiceApplyFieldMakeInvoiceStatusState;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceApply.makeInvoiceStatus.state.concrete.InvoiceApplyFieldMakeInvoiceStatusConcreteState_0_待开票;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceApply.makeInvoiceStatus.state.concrete.InvoiceApplyFieldMakeInvoiceStatusConcreteState_10_开票中;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceApply.makeInvoiceStatus.state.concrete.InvoiceApplyFieldMakeInvoiceStatusConcreteState_1_已开票;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceApply.makeInvoiceStatus.state.concrete.InvoiceApplyFieldMakeInvoiceStatusConcreteState_2_重新开票;
import lombok.Data;

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

    private InvoiceApplyFieldMakeInvoiceStatusState state_0_待开票;
    private InvoiceApplyFieldMakeInvoiceStatusState state_2_重新开票;
    private InvoiceApplyFieldMakeInvoiceStatusState state_10_开票中;
    private InvoiceApplyFieldMakeInvoiceStatusState state_1_已开票;

    private InvoiceApplyFieldMakeInvoiceStatusState state;

    private SzhtxxInvoiceFptxxOpSingleBillingForm form;

    private InvoiceApply entity;

    private LoginSysUser loginSysUser;


    public InvoiceApplyFieldMakeInvoiceStatusContext(InvoiceApply entity, LoginSysUser loginSysUser) {

        this.state_0_待开票 = new InvoiceApplyFieldMakeInvoiceStatusConcreteState_0_待开票(this);
        this.state_2_重新开票 = new InvoiceApplyFieldMakeInvoiceStatusConcreteState_2_重新开票(this);
        this.state_10_开票中 = new InvoiceApplyFieldMakeInvoiceStatusConcreteState_10_开票中(this);
        this.state_1_已开票 = new InvoiceApplyFieldMakeInvoiceStatusConcreteState_1_已开票(this);


        this.entity = entity;
        this.loginSysUser = loginSysUser;

        switch (InvoiceApplyCustomerMakeInvoiceStatusEnum.get(this.entity.getMakeInvoiceStatus())) {

            case 待开票:
                state = state_0_待开票;
                break;
            case 重新开票:
                state = state_2_重新开票;
                break;
            case 开票中:
                state = state_10_开票中;
                break;
            case 已开票:
                state = state_1_已开票;
                break;

            default:
//				state = state_0_待开票;
                break;

        }
    }

    public InvoiceApplyFieldMakeInvoiceStatusContext(SzhtxxInvoiceFptxxOpSingleBillingForm form, InvoiceApply entity, LoginSysUser loginSysUser) {

        this.state_0_待开票 = new InvoiceApplyFieldMakeInvoiceStatusConcreteState_0_待开票(this);
        this.state_2_重新开票 = new InvoiceApplyFieldMakeInvoiceStatusConcreteState_2_重新开票(this);
        this.state_10_开票中 = new InvoiceApplyFieldMakeInvoiceStatusConcreteState_10_开票中(this);
        this.state_1_已开票 = new InvoiceApplyFieldMakeInvoiceStatusConcreteState_1_已开票(this);


        this.form = form;
        this.entity = entity;
        this.loginSysUser = loginSysUser;

        switch (InvoiceApplyCustomerMakeInvoiceStatusEnum.get(this.entity.getMakeInvoiceStatus())) {

            case 待开票:
                state = state_0_待开票;
                break;
            case 重新开票:
                state = state_2_重新开票;
                break;
            case 开票中:
                state = state_10_开票中;
                break;
            case 已开票:
                state = state_1_已开票;
                break;

            default:
//				state = state_0_待开票;
                break;

        }
    }

    // 待开票(0, "待开票"),
    public SysNotify opInit() {
        return state.opInit();
    }

    // 已作废(2, "已作废"),
    public SysNotify opBecomeInvalid() {
        return state.opBecomeInvalid();
    }

    // 开票中(10, "开票中"),
    public SysNotify opOngoing() {
        return state.opOngoing();
    }

    // 已开票(11, "已开票"),
    public SysNotify opComplete() {
        return state.opComplete();
    }


    @Override
    public String toString() {
        return "状态 :" + getState().getClass().getName();
    }
}
