package cn.superdesk.uniorder.pattern.state.accounting.supplier.accountingUnifiedSupplier.accountingStatus.context;

import cn.superdesk.uniorder.common.enums.accounting.supplier.AccountingOrderSupplierAccountingStatusEnum;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.accounting.unified.supplier.AccountingUnifiedSupplier;
import cn.superdesk.uniorder.pattern.state.accounting.supplier.accountingUnifiedSupplier.accountingStatus.state.AccountingUnifiedSupplierFieldAccountingStatusState;
import cn.superdesk.uniorder.pattern.state.accounting.supplier.accountingUnifiedSupplier.accountingStatus.state.concrete.*;
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 AccountingUnifiedSupplierFieldAccountingStatusContext {

	private AccountingUnifiedSupplierFieldAccountingStatusState state_3_待提交;
	private AccountingUnifiedSupplierFieldAccountingStatusState state_0_未确认;
	private AccountingUnifiedSupplierFieldAccountingStatusState state_1_已确认;
	private AccountingUnifiedSupplierFieldAccountingStatusState state_2_已拒绝;
	private AccountingUnifiedSupplierFieldAccountingStatusState state_minus1_已取消;

	private AccountingUnifiedSupplierFieldAccountingStatusState state;

	private AccountingUnifiedSupplier entity;

	private LoginSysUser loginSysUser;


	public AccountingUnifiedSupplierFieldAccountingStatusContext(AccountingUnifiedSupplier entity, LoginSysUser loginSysUser) {

		this.state_3_待提交 = new AccountingUnifiedSupplierFieldAccountingStatusConcreteState_3_待提交(this);
		this.state_0_未确认 = new AccountingUnifiedSupplierFieldAccountingStatusConcreteState_0_未确认(this);
		this.state_1_已确认 = new AccountingUnifiedSupplierFieldAccountingStatusConcreteState_1_已确认(this);
		this.state_2_已拒绝 = new AccountingUnifiedSupplierFieldAccountingStatusConcreteState_2_已拒绝(this);
		this.state_minus1_已取消 = new AccountingUnifiedSupplierFieldAccountingStatusConcreteState_minus1_已取消(this);


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

		switch (AccountingOrderSupplierAccountingStatusEnum.get(this.entity.getAccountingStatus())) {

			case 待提交:
				state = state_3_待提交;
				break;
			case 未确认:
				state = state_0_未确认;
				break;
			case 已确认:
				state = state_1_已确认;
				break;
			case 已拒绝:
				state = state_2_已拒绝;
				break;
			case 已取消:
				state = state_minus1_已取消;
				break;

			default:
				state = state_3_待提交;
				break;

		}
	}

	// 待提交(3, "待提交"),
	public void opInitOrReset() {
		state.opInitOrReset();
	}

	// 未确认(0, "未确认"),
	public void opSubmit() {
		state.opSubmit();
	}

	// 已确认(1, "已确认"),
	public void opConfirm() {
		state.opConfirm();
	}

	// 已拒绝(2, "已拒绝"),
	public void opReject() {
		state.opReject();
	}

	// 已取消(-1, "已取消"),
	public void opCancel() {
		state.opCancel();
	}


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