package cn.superdesk.uniorder.dubbo.consumer.invoice.customer.state;

import cn.superdesk.uniorder.common.security.JwtUtil;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.invoice.customer.InvoiceApply;
import cn.superdesk.uniorder.dto.param.invoice.customer.status.OpBackAccountStatusForm;
import cn.superdesk.uniorder.dubbo.consumer._permission.PermissionDubboCustomerService;
import cn.superdesk.uniorder.dubbo.facade.invoice.customer.state.DubboInvoiceApplyFieldBackAccountStatusService;
import com.alibaba.dubbo.config.annotation.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;


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

	@Reference(version = "1.0.0", timeout = 300000, retries = -1)
	private DubboInvoiceApplyFieldBackAccountStatusService dubboInvoiceApplyFieldBackAccountStatusService;

	@Resource
	private PermissionDubboCustomerService permissionDubboCustomerService;

	/****************************************** 状态机 外部使用 类门面 start ******************************************/
	// 状态流转为 未回款(0, "未回款")
	public void opInit(InvoiceApply entity, String token) {
		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
		dubboInvoiceApplyFieldBackAccountStatusService.opInit(entity, loginSysUser);
	}

	// 状态流转为 部分回款(1, "部分回款")
	public void opPart(InvoiceApply entity, String token) {
		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
		dubboInvoiceApplyFieldBackAccountStatusService.opPart(entity, loginSysUser);
	}

	// 状态流转为 已回款(2, "已回款")
	public void opComplete(InvoiceApply entity, String token) {
		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
		dubboInvoiceApplyFieldBackAccountStatusService.opComplete(entity, loginSysUser);
	}

	// 状态流转为 已回款(2, "已回款")
	public void opComplete(List<InvoiceApply> entitys, OpBackAccountStatusForm form, String token) {
		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);
		dubboInvoiceApplyFieldBackAccountStatusService.opComplete(entitys, form, loginSysUser);
	}

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