package cn.superdesk.uniorder.service.invoice.customer.invoiced.impl;

import cn.hutool.core.date.DateUtil;
import cn.superdesk.uniorder.common.enums.common.CommonIsInvalidEnum;
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.service.invoice.customer.invoiced.InvoiceInvoicedFieldIsInvalidService;
import cn.superdesk.uniorder.service.invoice.customer.invoiced.InvoiceInvoicedService;
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 InvoiceInvoicedFieldIsInvalidServiceImpl implements InvoiceInvoicedFieldIsInvalidService {

	@Autowired
	private InvoiceInvoicedService invoiceInvoicedService;

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

	// 状态流转为 正常(0, "正常")
	public void opInitOrBeValidByStateMachine(InvoiceInvoiced entity, LoginSysUser loginSysUser) {

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

		// TODO 更新状态逻辑...
		forUpdate.setUpdateTime(DateUtil.date());
		forUpdate.setUpdateUserId(loginSysUser.getSysUserId());
		forUpdate.setUpdateUserName(loginSysUser.getFullName());

		forUpdate.setIsInvalid(CommonIsInvalidEnum.正常.getKey());

		invoiceInvoicedService.updateInvoiceInvoicedByPrimaryKeySelective(forUpdate);
	}

	// 状态流转为 作废(1, "作废")
	public void opBecomeInvalidByStateMachine(InvoiceInvoiced entity, LoginSysUser loginSysUser) {

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

		// TODO 更新状态逻辑...
		forUpdate.setUpdateTime(DateUtil.date());
		forUpdate.setUpdateUserId(loginSysUser.getSysUserId());
		forUpdate.setUpdateUserName(loginSysUser.getFullName());

		forUpdate.setIsInvalid(CommonIsInvalidEnum.作废.getKey());

		invoiceInvoicedService.updateInvoiceInvoicedByPrimaryKeySelective(forUpdate);
	}

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


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

	// 状态流转为 正常(0, "正常")
	public void opInitOrBeValid(InvoiceInvoiced entity, LoginSysUser loginSysUser) {
		InvoiceInvoicedFieldIsInvalidContext context = new InvoiceInvoicedFieldIsInvalidContext(entity, loginSysUser);
		context.opInitOrBeValid();
	}

	// 状态流转为 作废(1, "作废")
	public void opBecomeInvalid(InvoiceInvoiced entity, LoginSysUser loginSysUser) {
		InvoiceInvoicedFieldIsInvalidContext context = new InvoiceInvoicedFieldIsInvalidContext(entity, loginSysUser);
		context.opBecomeInvalid();
	}

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