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

import cn.superdesk.uniorder.common.enums.invoice.InvoiceApplyDimEnum;
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.dto.param.invoice.supplier.status.InvoiceApplySupplierOpReceiveInvoiceStatusForm;
import cn.superdesk.uniorder.pattern.state.invoice.supplier.invoiceApplySupplier.receiveInvoiceStatus.context.InvoiceApplySupplierFieldReceiveInvoiceStatusContext;
import cn.superdesk.uniorder.pattern.state.invoice.supplier.invoiceApplySupplier.receiveInvoiceStatus.state.InvoiceApplySupplierFieldReceiveInvoiceStatusState;
import cn.superdesk.uniorder.service.invoice.supplier.InvoiceApplySupplierFieldReceiveInvoiceStatusService;
import cn.superdesk.uniorder.service.invoice.supplier.InvoiceApplySupplierService;
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 InvoiceApplySupplierFieldReceiveInvoiceStatusConcreteState_0_未收票 implements InvoiceApplySupplierFieldReceiveInvoiceStatusState {

	private InvoiceApplySupplierService                          invoiceApplySupplierService;
	private InvoiceApplySupplierFieldReceiveInvoiceStatusService invoiceApplySupplierFieldReceiveInvoiceStatusService;

	private InvoiceApplySupplierFieldReceiveInvoiceStatusContext context;

	public InvoiceApplySupplierFieldReceiveInvoiceStatusConcreteState_0_未收票(InvoiceApplySupplierFieldReceiveInvoiceStatusContext context) {
		this.context = context;
		this.invoiceApplySupplierService = (InvoiceApplySupplierService) SpringContextHolder.getBean(InvoiceApplySupplierService.class);
		this.invoiceApplySupplierFieldReceiveInvoiceStatusService = (InvoiceApplySupplierFieldReceiveInvoiceStatusService) SpringContextHolder.getBean(InvoiceApplySupplierFieldReceiveInvoiceStatusService.class);
	}

	// 供应商|商户 开票后 发票 寄出 寄给 侨城汇-运营 此时侨城汇-运营 未收票 -> 状态 -> 未收票(0, "未收票")
	public void opInit() {

		log.info("供应商|商户 开票后 发票 寄出 寄给 侨城汇-运营 此时侨城汇-运营 未收票 -> 状态 -> {} -> 未收票(0, \"未收票\")", getClass().getName());


		LoginSysUser        loginSysUser        = context.getLoginSysUser();

		InvoiceApplyDimEnum invoiceApplyDimEnum = context.getInvoiceApplyDimEnum();
		switch (invoiceApplyDimEnum) {
			case 票申请:

				InvoiceApplySupplier entity = context.getEntity();
				invoiceApplySupplierFieldReceiveInvoiceStatusService.opInitByStateMachine(entity, loginSysUser);

				break;
			case 对账单:

//				List<InvoiceApplySupplier> entitys = context.getEntitys();
//				InvoiceApplySupplierOpReceiveInvoiceStatusForm form = context.getForm();
//				invoiceApplySupplierFieldReceiveInvoiceStatusService.opInitByStateMachine(entitys, form, loginSysUser);

				break;
		}


	}

	// 侨城汇-运营 op收票登记 发票 寄到后 侨城汇-运营 收到邮件后 此时侨城汇-运营 登记收票 填写发票号 上传凭证等等资料 此时侨城汇-运营 已收票 -> 状态 -> 已收票(1, "已收票")
	public void opReceive() {

		log.info("侨城汇-运营 op收票登记 发票 寄到后 侨城汇-运营 收到邮件后 此时侨城汇-运营 登记收票 填写发票号 上传凭证等等资料 此时侨城汇-运营 已收票 -> 状态 -> {} -> 已收票(1, \"已收票\")", getClass().getName());

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


		switch (invoiceApplyDimEnum) {
			case 票申请:

				InvoiceApplySupplier entity = context.getEntity();
				invoiceApplySupplierFieldReceiveInvoiceStatusService.opReceiveByStateMachine(entity, loginSysUser);

				break;
			case 对账单:

				List<InvoiceApplySupplier> entitys = context.getEntitys();
				InvoiceApplySupplierOpReceiveInvoiceStatusForm form = context.getForm();
				invoiceApplySupplierFieldReceiveInvoiceStatusService.opReceiveByStateMachine(entitys, form, loginSysUser);

				break;
		}
	}

}