package cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isInvalid.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.isInvalid.context.InvoiceInvoicedFieldIsInvalidContext;
import cn.superdesk.uniorder.pattern.state.invoice.customer.invoiceInvoiced.isInvalid.state.InvoiceInvoicedFieldIsInvalidState;
import cn.superdesk.uniorder.service.invoice.customer.invoiced.InvoiceInvoicedFieldIsInvalidService;
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 InvoiceInvoicedFieldIsInvalidConcreteState_1_作废 implements InvoiceInvoicedFieldIsInvalidState {

	private InvoiceInvoicedService               invoiceInvoicedService;
	private InvoiceInvoicedFieldIsInvalidService invoiceInvoicedFieldIsInvalidService;

	private InvoiceInvoicedFieldIsInvalidContext context;

	public InvoiceInvoicedFieldIsInvalidConcreteState_1_作废(InvoiceInvoicedFieldIsInvalidContext context) {
		this.context = context;
		this.invoiceInvoicedService = (InvoiceInvoicedService) SpringContextHolder.getBean(InvoiceInvoicedService.class);
		this.invoiceInvoicedFieldIsInvalidService = (InvoiceInvoicedFieldIsInvalidService) SpringContextHolder.getBean(InvoiceInvoicedFieldIsInvalidService.class);
	}

	// 初始化或反作废 -> 状态 -> 正常(0, "正常")
	public void opInitOrBeValid() {

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

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

		invoiceInvoicedFieldIsInvalidService.opInitOrBeValidByStateMachine(entity, loginSysUser);
	}

	// 作废 -> 状态 -> 作废(1, "作废")
	public void opBecomeInvalid() {

		log.info("作废 -> 状态 -> {} -> 作废(1, \"作废\")", getClass().getName());

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

		invoiceInvoicedFieldIsInvalidService.opBecomeInvalidByStateMachine(entity, loginSysUser);
	}

}
