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

import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.invoice.customer.invoiced.InvoiceInvoiced;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isRedWriteOff.context.InvoiceInvoicedFieldIsRedWriteOffContext;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isRedWriteOff.state.InvoiceInvoicedFieldIsRedWriteOffState;
import cn.superdesk.uniorder.service.invoice.customer.invoiced.InvoiceInvoicedFieldIsRedWriteOffService;
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 InvoiceInvoicedFieldIsRedWriteOffConcreteState_1_是 implements InvoiceInvoicedFieldIsRedWriteOffState {

	private InvoiceInvoicedService                   invoiceInvoicedService;
	private InvoiceInvoicedFieldIsRedWriteOffService invoiceInvoicedFieldIsRedWriteOffService;

	private InvoiceInvoicedFieldIsRedWriteOffContext context;

	public InvoiceInvoicedFieldIsRedWriteOffConcreteState_1_是(InvoiceInvoicedFieldIsRedWriteOffContext context) {
		this.context = context;
		this.invoiceInvoicedService = (InvoiceInvoicedService) SpringContextHolder.getBean(InvoiceInvoicedService.class);
		this.invoiceInvoicedFieldIsRedWriteOffService = (InvoiceInvoicedFieldIsRedWriteOffService) SpringContextHolder.getBean(InvoiceInvoicedFieldIsRedWriteOffService.class);
	}

	// 初始化 -> 状态 -> 否(0, "否")
	public void opInit() {

		log.info("初始化 -> 状态 -> {} -> 否(0, \"否\")", getClass().getName());

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

		invoiceInvoicedFieldIsRedWriteOffService.opInitByStateMachine(entity, loginSysUser);
	}

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

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

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

		invoiceInvoicedFieldIsRedWriteOffService.opRedWriteOffByStateMachine(entity, loginSysUser);
	}

}
