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

import cn.hutool.core.date.DateUtil;
import cn.superdesk.uniorder.common.enums.invoice.InvoiceInvoicedIsRedWriteOffEnum;
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.service.invoice.customer.invoiced.InvoiceInvoicedFieldIsRedWriteOffService;
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 InvoiceInvoicedFieldIsRedWriteOffServiceImpl implements InvoiceInvoicedFieldIsRedWriteOffService {

	@Autowired
	private InvoiceInvoicedService invoiceInvoicedService;

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

	// 状态流转为 否(0, "否")
	public void opInitByStateMachine(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.setIsRedWriteOff(InvoiceInvoicedIsRedWriteOffEnum.否.getKey());

		invoiceInvoicedService.updateInvoiceInvoicedByPrimaryKeySelective(forUpdate);
	}

	// 状态流转为 是(1, "是")
	public void opRedWriteOffByStateMachine(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.setIsRedWriteOff(InvoiceInvoicedIsRedWriteOffEnum.是.getKey());

		invoiceInvoicedService.updateInvoiceInvoicedByPrimaryKeySelective(forUpdate);
	}

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


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

	// 状态流转为 否(0, "否")
	public void opInit(InvoiceInvoiced entity, LoginSysUser loginSysUser) {
		InvoiceInvoicedFieldIsRedWriteOffContext context = new InvoiceInvoicedFieldIsRedWriteOffContext(entity, loginSysUser);
		context.opInit();
	}

	// 状态流转为 是(1, "是")
	public void opRedWriteOff(InvoiceInvoiced entity, LoginSysUser loginSysUser) {
		InvoiceInvoicedFieldIsRedWriteOffContext context = new InvoiceInvoicedFieldIsRedWriteOffContext(entity, loginSysUser);
		context.opRedWriteOff();
	}

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