package cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isBackCollection.context;

import cn.superdesk.uniorder.common.enums.invoice.customer.InvoiceApplyCustomerBackAccountStatusEnum;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.invoice.customer.invoiced.InvoiceInvoiced;
import cn.superdesk.uniorder.dto.param.invoice.excel.InvoiceInvoicedOpBackCollectionForm;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isBackCollection.state.InvoiceInvoicedFieldIsBackCollectionState;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isBackCollection.state.concrete.InvoiceInvoicedFieldIsBackCollectionConcreteState_0_未回款;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isBackCollection.state.concrete.InvoiceInvoicedFieldIsBackCollectionConcreteState_1_部分回款;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isBackCollection.state.concrete.InvoiceInvoicedFieldIsBackCollectionConcreteState_2_已回款;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isBackCollection.state.concrete.InvoiceInvoicedFieldIsBackCollectionConcreteState_69_红冲发票;
import lombok.Data;

/**
 * @Description: 简易状态机 星型结构
 * @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 InvoiceInvoicedFieldIsBackCollectionContext {

	private InvoiceInvoicedFieldIsBackCollectionState state_0_未回款;
	private InvoiceInvoicedFieldIsBackCollectionState state_1_部分回款;
	private InvoiceInvoicedFieldIsBackCollectionState state_2_已回款;
	private InvoiceInvoicedFieldIsBackCollectionState state_69_红冲发票;

	private InvoiceInvoicedFieldIsBackCollectionState state;

	private InvoiceInvoiced                     entity;
	private InvoiceInvoicedOpBackCollectionForm form;

	private LoginSysUser loginSysUser;


	public InvoiceInvoicedFieldIsBackCollectionContext(InvoiceInvoiced entity, InvoiceInvoicedOpBackCollectionForm form, LoginSysUser loginSysUser) {

		this.state_0_未回款 = new InvoiceInvoicedFieldIsBackCollectionConcreteState_0_未回款(this);
		this.state_1_部分回款 = new InvoiceInvoicedFieldIsBackCollectionConcreteState_1_部分回款(this);
		this.state_2_已回款 = new InvoiceInvoicedFieldIsBackCollectionConcreteState_2_已回款(this);
		this.state_69_红冲发票 = new InvoiceInvoicedFieldIsBackCollectionConcreteState_69_红冲发票(this);

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

		switch (InvoiceApplyCustomerBackAccountStatusEnum.get(this.entity.getIsBackCollection())) {

			case 未回款:
				state = state_0_未回款;
				break;
			case 部分回款:
				state = state_1_部分回款;
				break;
			case 已回款:
				state = state_2_已回款;
				break;
			case 发票红冲:
				state = state_69_红冲发票;
				break;

			default:
//				state = state_0_未回款;
				break;

		}
	}

	// 未回款(0, "未回款"),
	public void opInitOrReset() {
		state.opInitOrReset();
	}

	// 部分回款(1, "部分回款"),
	public void opPart() {
		state.opPart();
	}

	// 全部回款(2, "全部回款"),
	public void opComplete() {
		state.opComplete();
	}

	// 红冲发票(69, "红冲发票"),
	public void opRedWriteOff() {
		state.opRedWriteOff();
	}


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