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

import cn.superdesk.uniorder.common.enums.common.CommonIsInvalidEnum;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.invoice.customer.invoiced.InvoiceInvoiced;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isInvalid.state.InvoiceInvoicedFieldIsInvalidState;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isInvalid.state.concrete.InvoiceInvoicedFieldIsInvalidConcreteState_0_正常;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isInvalid.state.concrete.InvoiceInvoicedFieldIsInvalidConcreteState_1_作废;
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 InvoiceInvoicedFieldIsInvalidContext {

	private InvoiceInvoicedFieldIsInvalidState state_0_正常;
	private InvoiceInvoicedFieldIsInvalidState state_1_作废;

	private InvoiceInvoicedFieldIsInvalidState state;

	private InvoiceInvoiced entity;

	private LoginSysUser loginSysUser;


	public InvoiceInvoicedFieldIsInvalidContext(InvoiceInvoiced entity, LoginSysUser loginSysUser) {

		this.state_0_正常 = new InvoiceInvoicedFieldIsInvalidConcreteState_0_正常(this);
		this.state_1_作废 = new InvoiceInvoicedFieldIsInvalidConcreteState_1_作废(this);


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

		switch (CommonIsInvalidEnum.get(this.entity.getIsInvalid())) {

			case 正常:
				state = state_0_正常;
				break;
			case 作废:
				state = state_1_作废;
				break;

			default:
//				state = state_0_正常;
				break;

		}
	}

	// 正常(0, "正常"),
	public void opInitOrBeValid() {
		state.opInitOrBeValid();
	}

	// 作废(1, "作废"),
	public void opBecomeInvalid() {
		state.opBecomeInvalid();
	}


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