package cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.deleted.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.deleted.context.InvoiceInvoicedFieldDeletedContext;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.deleted.state.InvoiceInvoicedFieldDeletedState;
import cn.superdesk.uniorder.service.invoice.customer.invoiced.InvoiceInvoicedFieldDeletedService;
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 InvoiceInvoicedFieldDeletedConcreteState_0_正常 implements InvoiceInvoicedFieldDeletedState {

	private InvoiceInvoicedService             invoiceInvoicedService;
	private InvoiceInvoicedFieldDeletedService invoiceInvoicedFieldDeletedService;

	private InvoiceInvoicedFieldDeletedContext context;

	public InvoiceInvoicedFieldDeletedConcreteState_0_正常(InvoiceInvoicedFieldDeletedContext context) {
		this.context = context;
		this.invoiceInvoicedService = (InvoiceInvoicedService) SpringContextHolder.getBean(InvoiceInvoicedService.class);
		this.invoiceInvoicedFieldDeletedService = (InvoiceInvoicedFieldDeletedService) SpringContextHolder.getBean(InvoiceInvoicedFieldDeletedService.class);
	}

	// 初始化或恢复 -> 状态 -> 正常(0, "正常")
	public void opInit() {

		log.info("初始化或恢复 -> 状态 -> {} -> 正常(0, \"正常\")", getClass().getName());

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

		invoiceInvoicedFieldDeletedService.opInitByStateMachine(entity, loginSysUser);
	}

	// 软删除 -> 状态 -> 删除(1, "删除")
	public void opDelete() {

		log.info("软删除 -> 状态 -> {} -> 删除(1, \"删除\")", getClass().getName());

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

		invoiceInvoicedFieldDeletedService.opDeleteByStateMachine(entity, loginSysUser);
	}

}
