package cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceApply.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.customer.InvoiceApply;
import cn.superdesk.uniorder.dto.param.invoice.customer.status.InvoiceApplyCustomerOpReceiveInvoiceStatusForm;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceApply.receiveInvoiceStatus.context.InvoiceApplyFieldReceiveInvoiceStatusContext;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceApply.receiveInvoiceStatus.state.InvoiceApplyFieldReceiveInvoiceStatusState;
import cn.superdesk.uniorder.service.invoice.customer.state.InvoiceApplyCustomerFieldReceiveInvoiceStatusService;
import cn.superdesk.uniorder.service.invoice.customer.InvoiceApplyCustomerService;
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 InvoiceApplyFieldReceiveInvoiceStatusConcreteState_0_未领票 implements InvoiceApplyFieldReceiveInvoiceStatusState {

	private InvoiceApplyCustomerService                          invoiceApplyService;
	private InvoiceApplyCustomerFieldReceiveInvoiceStatusService invoiceApplyFieldReceiveInvoiceStatusService;

	private InvoiceApplyFieldReceiveInvoiceStatusContext context;

	public InvoiceApplyFieldReceiveInvoiceStatusConcreteState_0_未领票(InvoiceApplyFieldReceiveInvoiceStatusContext context) {
		this.context = context;
		this.invoiceApplyService = (InvoiceApplyCustomerService) SpringContextHolder.getBean(InvoiceApplyCustomerService.class);
		this.invoiceApplyFieldReceiveInvoiceStatusService = (InvoiceApplyCustomerFieldReceiveInvoiceStatusService) SpringContextHolder.getBean(InvoiceApplyCustomerFieldReceiveInvoiceStatusService.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();
				invoiceApplyFieldReceiveInvoiceStatusService.opInitByStateMachine(entity, loginSysUser);

				break;
			case 对账单:

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

				break;
		}


	}

	// 运营领票 -> 状态 -> 已领票(1, "已领票")
	public void opReceive() {

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

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

		switch (invoiceApplyDimEnum) {
			case 票申请:

				InvoiceApply entity = context.getEntity();
				invoiceApplyFieldReceiveInvoiceStatusService.opReceiveByStateMachine(entity, loginSysUser);

				break;
			case 对账单:

				List<InvoiceApply> entitys = context.getEntitys();
				InvoiceApplyCustomerOpReceiveInvoiceStatusForm form = context.getForm();
				invoiceApplyFieldReceiveInvoiceStatusService.opReceiveByStateMachine(entitys, form, loginSysUser);

				break;
		}
	}

}