package cn.superdesk.uniorder.pattern.state.invoice.supplier.invoiceApplySupplier.mailTickStatus.state.concrete;

import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.common.spring.SpringContextHolder;
import cn.superdesk.uniorder.dao.entity.invoice.supplier.InvoiceApplySupplier;
import cn.superdesk.uniorder.pattern.state.invoice.supplier.invoiceApplySupplier.mailTickStatus.context.InvoiceApplySupplierFieldMailTickStatusContext;
import cn.superdesk.uniorder.pattern.state.invoice.supplier.invoiceApplySupplier.mailTickStatus.state.InvoiceApplySupplierFieldMailTickStatusState;
import cn.superdesk.uniorder.service.invoice.supplier.InvoiceApplySupplierFieldMailTickStatusService;
import cn.superdesk.uniorder.service.invoice.supplier.InvoiceApplySupplierService;
import lombok.AllArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

/**
 * @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 InvoiceApplySupplierFieldMailTickStatusConcreteState_0_未邮寄 implements InvoiceApplySupplierFieldMailTickStatusState {

	private InvoiceApplySupplierService                    invoiceApplySupplierService;
	private InvoiceApplySupplierFieldMailTickStatusService invoiceApplySupplierFieldMailTickStatusService;

	private InvoiceApplySupplierFieldMailTickStatusContext context;

	public InvoiceApplySupplierFieldMailTickStatusConcreteState_0_未邮寄(InvoiceApplySupplierFieldMailTickStatusContext context) {
		this.context = context;
		this.invoiceApplySupplierService = (InvoiceApplySupplierService) SpringContextHolder.getBean(InvoiceApplySupplierService.class);
		this.invoiceApplySupplierFieldMailTickStatusService = (InvoiceApplySupplierFieldMailTickStatusService) SpringContextHolder.getBean(InvoiceApplySupplierFieldMailTickStatusService.class);
	}

	// 供应商|商户 开票后 未寄出 -> 状态 -> 未邮寄(0, "未邮寄")
	public void opInit() {

		log.info("供应商|商户 开票后 未寄出 -> 状态 -> {} -> 未邮寄(0, \"未邮寄\")", getClass().getName());

		InvoiceApplySupplier entity       = context.getEntity();
		LoginSysUser         loginSysUser = context.getLoginSysUser();

		invoiceApplySupplierFieldMailTickStatusService.opInitByStateMachine(entity, loginSysUser);
	}

	// 供应商|商户 op寄票登记 开票后 寄出发票 -> 状态 -> 已邮寄(1, "已邮寄")
	public void opComplete() {

		log.info("供应商|商户 op寄票登记 开票后 寄出发票 -> 状态 -> {} -> 已邮寄(1, \"已邮寄\")", getClass().getName());

		InvoiceApplySupplier entity       = context.getEntity();
		LoginSysUser         loginSysUser = context.getLoginSysUser();

		invoiceApplySupplierFieldMailTickStatusService.opCompleteByStateMachine(entity, loginSysUser);
	}

}