package cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isBackCollection.state.concrete;

import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.invoice.customer.invoiced.InvoiceInvoiced;
import cn.superdesk.uniorder.dto.param.invoice.excel.InvoiceInvoicedOpBackCollectionForm;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isBackCollection.context.InvoiceInvoicedFieldIsBackCollectionContext;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isBackCollection.state.InvoiceInvoicedFieldIsBackCollectionState;
import cn.superdesk.uniorder.service.invoice.customer.invoiced.InvoiceInvoicedFieldIsBackCollectionService;
import cn.superdesk.uniorder.service.invoice.customer.invoiced.InvoiceInvoicedService;
import cn.superdesk.uniorder.common.spring.SpringContextHolder;
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 InvoiceInvoicedFieldIsBackCollectionConcreteState_1_部分回款 implements InvoiceInvoicedFieldIsBackCollectionState {

	private InvoiceInvoicedService                      invoiceInvoicedService;
	private InvoiceInvoicedFieldIsBackCollectionService invoiceInvoicedFieldIsBackCollectionService;

	private InvoiceInvoicedFieldIsBackCollectionContext context;

	public InvoiceInvoicedFieldIsBackCollectionConcreteState_1_部分回款(InvoiceInvoicedFieldIsBackCollectionContext context) {
		this.context = context;
		this.invoiceInvoicedService = (InvoiceInvoicedService) SpringContextHolder.getBean(InvoiceInvoicedService.class);
		this.invoiceInvoicedFieldIsBackCollectionService = (InvoiceInvoicedFieldIsBackCollectionService) SpringContextHolder.getBean(InvoiceInvoicedFieldIsBackCollectionService.class);
	}

	// 初始化或重置 -> 状态 -> 未回款(0, "未回款")
	public void opInitOrReset() {

		log.info("初始化或重置 -> 状态 -> {} -> 未回款(0, \"未回款\")", getClass().getName());

		InvoiceInvoiced                     entity       = context.getEntity();
		InvoiceInvoicedOpBackCollectionForm form         = context.getForm();
		LoginSysUser                        loginSysUser = context.getLoginSysUser();

		invoiceInvoicedFieldIsBackCollectionService.opInitOrResetByStateMachine(entity, form, loginSysUser);
	}

	// 登记回款-部分回款 -> 状态 -> 部分回款(1, "部分回款")
	public void opPart() {

		log.info("登记回款-部分回款 -> 状态 -> {} -> 部分回款(1, \"部分回款\")", getClass().getName());

		InvoiceInvoiced                     entity       = context.getEntity();
		InvoiceInvoicedOpBackCollectionForm form         = context.getForm();
		LoginSysUser                        loginSysUser = context.getLoginSysUser();

		invoiceInvoicedFieldIsBackCollectionService.opPartByStateMachine(entity, form, loginSysUser);
	}

	// 登记回款-全部回款 -> 状态 -> 全部回款(2, "全部回款")
	public void opComplete() {

		log.info("登记回款-全部回款 -> 状态 -> {} -> 全部回款(2, \"全部回款\")", getClass().getName());

		InvoiceInvoiced                     entity       = context.getEntity();
		InvoiceInvoicedOpBackCollectionForm form         = context.getForm();
		LoginSysUser                        loginSysUser = context.getLoginSysUser();

		invoiceInvoicedFieldIsBackCollectionService.opCompleteByStateMachine(entity, form, loginSysUser);
	}

	// 红冲发票 -> 状态 -> 红冲发票(69, "红冲发票")
	public void opRedWriteOff() {

		log.info("红冲发票 -> 状态 -> {} -> 红冲发票(69, \"红冲发票\")", getClass().getName());

		InvoiceInvoiced                     entity       = context.getEntity();
		InvoiceInvoicedOpBackCollectionForm form         = context.getForm();
		LoginSysUser                        loginSysUser = context.getLoginSysUser();

		invoiceInvoicedFieldIsBackCollectionService.opRedWriteOffByStateMachine(entity, form, loginSysUser);
	}

}
