package cn.superdesk.uniorder.service.invoice.supplier.impl;

import cn.superdesk.uniorder.common.enums.invoice.supplier.InvoiceApplySupplierMailTickStatusEnum;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.invoice.supplier.InvoiceApplySupplier;
import cn.superdesk.uniorder.pattern.state.invoice.supplier.invoiceApplySupplier.mailTickStatus.context.InvoiceApplySupplierFieldMailTickStatusContext;
import cn.superdesk.uniorder.service.invoice.supplier.InvoiceApplySupplierFieldMailTickStatusService;
import cn.superdesk.uniorder.service.invoice.supplier.InvoiceApplySupplierService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: 简易状态机 星型结构
 * @Author: linjinyu
 * @CreateDate: 10/12/20 4:28 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 10/12/20 4:28 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Service
public class InvoiceApplySupplierFieldMailTickStatusServiceImpl implements InvoiceApplySupplierFieldMailTickStatusService {

	@Autowired
	private InvoiceApplySupplierService invoiceApplySupplierService;

	/****************************************** 状态机 公共方法 机内使用 实际流转 重用 start ******************************************/

	// 状态流转为 未邮寄(0, "未邮寄")
	public void opInitByStateMachine(InvoiceApplySupplier entity, LoginSysUser loginSysUser) {

		InvoiceApplySupplier forUpdate = new InvoiceApplySupplier();
		forUpdate.setId(entity.getId());

		// TODO 更新状态逻辑...

		forUpdate.setMailTickStatus(InvoiceApplySupplierMailTickStatusEnum.未邮寄.getKey());

		invoiceApplySupplierService.updateInvoiceApplySupplierByPrimaryKeySelective(forUpdate);
	}

	// 状态流转为 已邮寄(1, "已邮寄")
	public void opCompleteByStateMachine(InvoiceApplySupplier entity, LoginSysUser loginSysUser) {

		InvoiceApplySupplier forUpdate = new InvoiceApplySupplier();
		forUpdate.setId(entity.getId());

		// TODO 更新状态逻辑...

		forUpdate.setMailTickStatus(InvoiceApplySupplierMailTickStatusEnum.已邮寄.getKey());

		invoiceApplySupplierService.updateInvoiceApplySupplierByPrimaryKeySelective(forUpdate);
	}

	/****************************************** 状态机 公共方法 机内使用 实际流转 重用   end ******************************************/


	/****************************************** 状态机 外部使用 类门面 start ******************************************/

	// 状态流转为 未邮寄(0, "未邮寄")
	public void opInit(InvoiceApplySupplier entity, LoginSysUser loginSysUser) {
		InvoiceApplySupplierFieldMailTickStatusContext context = new InvoiceApplySupplierFieldMailTickStatusContext(entity, loginSysUser);
		context.opInit();
	}

	// 状态流转为 已邮寄(1, "已邮寄")
	public void opComplete(InvoiceApplySupplier entity, LoginSysUser loginSysUser) {
		InvoiceApplySupplierFieldMailTickStatusContext context = new InvoiceApplySupplierFieldMailTickStatusContext(entity, loginSysUser);
		context.opComplete();
	}

	/****************************************** 状态机 外部使用 类门面   end ******************************************/
}
