package cn.superdesk.uniorder.pattern.state.invoice.supplier.invoiceApplySupplier.makeInvoiceStatus.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.InvoiceApplySupplierOpCommonDimAccountingOrderForm;
import cn.superdesk.uniorder.pattern.state.invoice.supplier.invoiceApplySupplier.makeInvoiceStatus.context.InvoiceApplySupplierFieldMakeInvoiceStatusContext;
import cn.superdesk.uniorder.pattern.state.invoice.supplier.invoiceApplySupplier.makeInvoiceStatus.state.InvoiceApplySupplierFieldMakeInvoiceStatusState;
import cn.superdesk.uniorder.service.invoice.supplier.InvoiceApplySupplierFieldMakeInvoiceStatusService;
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 InvoiceApplySupplierFieldMakeInvoiceStatusConcreteState_2_已撤消 implements InvoiceApplySupplierFieldMakeInvoiceStatusState {

	private InvoiceApplySupplierService                       invoiceApplySupplierService;
	private InvoiceApplySupplierFieldMakeInvoiceStatusService invoiceApplySupplierFieldMakeInvoiceStatusService;

	private InvoiceApplySupplierFieldMakeInvoiceStatusContext context;

	public InvoiceApplySupplierFieldMakeInvoiceStatusConcreteState_2_已撤消(InvoiceApplySupplierFieldMakeInvoiceStatusContext context) {
		this.context = context;
		this.invoiceApplySupplierService = (InvoiceApplySupplierService) SpringContextHolder.getBean(InvoiceApplySupplierService.class);
		this.invoiceApplySupplierFieldMakeInvoiceStatusService = (InvoiceApplySupplierFieldMakeInvoiceStatusService) SpringContextHolder.getBean(InvoiceApplySupplierFieldMakeInvoiceStatusService.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();
				invoiceApplySupplierFieldMakeInvoiceStatusService.opInitByStateMachine(entity, loginSysUser);

				break;
			case 对账单:


				break;
		}


	}

	// 供应商|商户 op确认开票 已开票 -> 状态 -> 已开票(1, "已开票")
	public void opComplete() {

		log.info("供应商|商户 op确认开票 已开票 -> 状态 -> {} -> 已开票(1, \"已开票\")", getClass().getName());


		LoginSysUser loginSysUser = context.getLoginSysUser();

		InvoiceApplyDimEnum invoiceApplyDimEnum = context.getInvoiceApplyDimEnum();
		switch (invoiceApplyDimEnum) {
			case 票申请:
				InvoiceApplySupplier entity = context.getEntity();
				invoiceApplySupplierFieldMakeInvoiceStatusService.opCompleteByStateMachine(entity, loginSysUser);


				break;
			case 对账单:
				List<InvoiceApplySupplier> entitys = context.getEntitys();
				InvoiceApplySupplierOpCommonDimAccountingOrderForm form = context.getForm();
				invoiceApplySupplierFieldMakeInvoiceStatusService.opCompleteByStateMachine(entitys, form, loginSysUser);

				break;
		}


	}

	// 供应商|商户 op撤消开票 已撤消 -> 状态 -> 已撤消(2, "已撤消")
	public void opBecomeInvalid() {

		log.info("供应商|商户 op撤消开票 已撤消 -> 状态 -> {} -> 已撤消(2, \"已撤消\")", getClass().getName());


		LoginSysUser loginSysUser = context.getLoginSysUser();

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

				InvoiceApplySupplier entity = context.getEntity();
				invoiceApplySupplierFieldMakeInvoiceStatusService.opBecomeInvalidByStateMachine(entity, loginSysUser);

				break;
			case 对账单:


				break;
		}


	}

}