package cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceApply.mailTickStatus.state.concrete;

import cn.superdesk.uniorder.common.enums.invoice.InvoiceApplyDimEnum;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.invoice.customer.InvoiceApply;
import cn.superdesk.uniorder.dto.param.invoice.customer.status.OpMailTickStatusFormV2_1;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceApply.mailTickStatus.context.InvoiceApplyFieldMailTickStatusContext;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceApply.mailTickStatus.state.InvoiceApplyFieldMailTickStatusState;
import cn.superdesk.uniorder.service.invoice.customer.state.InvoiceApplyCustomerFieldMailTickStatusService;
import cn.superdesk.uniorder.service.invoice.customer.InvoiceApplyCustomerService;
import cn.superdesk.uniorder.common.spring.SpringContextHolder;
import lombok.AllArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @Description: 简易状态机 星型结构
 * @Author: linjinyu
 * @CreateDate: 9/23/20 2:00 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 9/23/20 2:00 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@ToString
@AllArgsConstructor
public class InvoiceApplyFieldMailTickStatusConcreteState_1_已邮寄 implements InvoiceApplyFieldMailTickStatusState {

	private InvoiceApplyCustomerService                    invoiceApplyService;
	private InvoiceApplyCustomerFieldMailTickStatusService invoiceApplyFieldMailTickStatusService;

	private InvoiceApplyFieldMailTickStatusContext context;

	public InvoiceApplyFieldMailTickStatusConcreteState_1_已邮寄(InvoiceApplyFieldMailTickStatusContext context) {
		this.context = context;
		this.invoiceApplyService = (InvoiceApplyCustomerService) SpringContextHolder.getBean(InvoiceApplyCustomerService.class);
		this.invoiceApplyFieldMailTickStatusService = (InvoiceApplyCustomerFieldMailTickStatusService) SpringContextHolder.getBean(InvoiceApplyCustomerFieldMailTickStatusService.class);
	}

	// 运营领票后准备寄出 -> 状态 -> 未邮寄(0, "未邮寄")
	public void opInit() {

		log.info("运营领票后准备寄出 -> 状态 -> {} -> 未邮寄(0, \"未邮寄\")", getClass().getName());

		InvoiceApplyDimEnum invoiceApplyDimEnum = context.getInvoiceApplyDimEnum();
		LoginSysUser        loginSysUser        = context.getLoginSysUser();

		switch (invoiceApplyDimEnum) {
			case 票申请:

				InvoiceApply entity = context.getEntity();
				invoiceApplyFieldMailTickStatusService.opInitByStateMachine(entity, loginSysUser);

				break;
			case 对账单:

//				List<InvoiceApply> entitys = context.getEntitys();
//				OpMailTickStatusForm form = context.getForm();
//				invoiceApplyFieldMailTickStatusService.opInitByStateMachine(entitys, form, loginSysUser);

				break;
		}
	}

	// 运营寄出发票 -> 状态 -> 已邮寄(1, "已邮寄")
	public void opComplete() {

		log.info("运营寄出发票 -> 状态 -> {} -> 已邮寄(1, \"已邮寄\")", getClass().getName());

		InvoiceApplyDimEnum invoiceApplyDimEnum = context.getInvoiceApplyDimEnum();
		LoginSysUser        loginSysUser        = context.getLoginSysUser();

		switch (invoiceApplyDimEnum) {
			case 票申请:

				InvoiceApply entity = context.getEntity();
				invoiceApplyFieldMailTickStatusService.opCompleteByStateMachine(entity, loginSysUser);

				break;
			case 对账单:

				List<InvoiceApply> entitys = context.getEntitys();
				OpMailTickStatusFormV2_1 form = context.getForm();
				invoiceApplyFieldMailTickStatusService.opCompleteByStateMachineV2_1(entitys, form, loginSysUser);

				break;
		}
	}

}