package cn.superdesk.uniorder.pattern.state.accounting.supplier.accountingUnifiedSupplier.accountingStatus.state.concrete;

import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.common.spring.SpringContextHolder;
import cn.superdesk.uniorder.dao.entity.accounting.unified.supplier.AccountingUnifiedSupplier;
import cn.superdesk.uniorder.pattern.state.accounting.supplier.accountingUnifiedSupplier.accountingStatus.context.AccountingUnifiedSupplierFieldAccountingStatusContext;
import cn.superdesk.uniorder.pattern.state.accounting.supplier.accountingUnifiedSupplier.accountingStatus.state.AccountingUnifiedSupplierFieldAccountingStatusState;
import cn.superdesk.uniorder.service.accounting.unified.supplier.AccountingUnifiedSupplierFieldAccountingStatusService;
import cn.superdesk.uniorder.service.accounting.unified.supplier.AccountingUnifiedSupplierService;
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 AccountingUnifiedSupplierFieldAccountingStatusConcreteState_2_已拒绝 implements AccountingUnifiedSupplierFieldAccountingStatusState {

	private AccountingUnifiedSupplierService                      accountingUnifiedSupplierService;
	private AccountingUnifiedSupplierFieldAccountingStatusService accountingUnifiedSupplierFieldAccountingStatusService;

	private AccountingUnifiedSupplierFieldAccountingStatusContext context;

	public AccountingUnifiedSupplierFieldAccountingStatusConcreteState_2_已拒绝(AccountingUnifiedSupplierFieldAccountingStatusContext context) {
		this.context = context;
		this.accountingUnifiedSupplierService = (AccountingUnifiedSupplierService) SpringContextHolder.getBean(AccountingUnifiedSupplierService.class);
		this.accountingUnifiedSupplierFieldAccountingStatusService = (AccountingUnifiedSupplierFieldAccountingStatusService) SpringContextHolder.getBean(AccountingUnifiedSupplierFieldAccountingStatusService.class);
	}

	// 刚创建时初始化状态'待提交'或重置状态为'待提交' -> 状态 -> 待提交(3, "待提交")
	public void opInitOrReset() {

		log.info("刚创建时初始化状态'待提交'或重置状态为'待提交' -> 状态 -> {} -> 待提交(3, \"待提交\")", getClass().getName());

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

		accountingUnifiedSupplierFieldAccountingStatusService.opInitOrResetByStateMachine(entity, loginSysUser);
	}

	// 刚创建时初始化状态'未确认'或重置状态为'未确认',内部_后端(待提交->已提交|未确认),外部_商户端(未确认|待确认) -> 状态 -> 未确认(0, "未确认")
	public void opSubmit() {

		log.info("刚创建时初始化状态'未确认'或重置状态为'未确认',内部_后端(待提交->已提交|未确认),外部_商户端(未确认|待确认) -> 状态 -> {} -> 未确认(0, \"未确认\")", getClass().getName());

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

		accountingUnifiedSupplierFieldAccountingStatusService.opSubmitByStateMachine(entity, loginSysUser);
	}

	// op确认对账:外部_商户端(未确认|待确认->已确认) -> 状态 -> 已确认(1, "已确认")
	public void opConfirm() {

		log.info("op确认对账:外部_商户端(未确认|待确认->已确认) -> 状态 -> {} -> 已确认(1, \"已确认\")", getClass().getName());

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

		accountingUnifiedSupplierFieldAccountingStatusService.opConfirmByStateMachine(entity, loginSysUser);
	}

	// op申斥对账:外部_商户端(未确认|待确认->已拒绝) -> 状态 -> 已拒绝(2, "已拒绝")
	public void opReject() {

		log.info("op申斥对账:外部_商户端(未确认|待确认->已拒绝) -> 状态 -> {} -> 已拒绝(2, \"已拒绝\")", getClass().getName());

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

		accountingUnifiedSupplierFieldAccountingStatusService.opRejectByStateMachine(entity, loginSysUser);
	}

	// op取消对账|op同意驳回 -> 状态 -> 已取消(-1, "已取消")
	public void opCancel() {

		log.info("op取消对账|op同意驳回 -> 状态 -> {} -> 已取消(-1, \"已取消\")", getClass().getName());

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

		accountingUnifiedSupplierFieldAccountingStatusService.opCancelByStateMachine(entity, loginSysUser);
	}

}