package digital.laboratory.platform.entrustment.misc;

import digital.laboratory.platform.entrustment.enums.EntrustmentStatusConstants;


/**
 * 流程映射定义
 */
public class ProcessFlowMapper {
	public static int getNextStatus(int currentStatus, int opCode) {
		int processFlowMapper[][] = {
				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_CREATED.getStatus(), 1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_CHECK_CLAIM.getStatus()},

				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_CHECK_CLAIM.getStatus(), 1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_CHECK.getStatus()},

				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_CHECK.getStatus(), 1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_APPROVE_CLAIM.getStatus()},
				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_CHECK.getStatus(), -1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_CREATED.getStatus()},

				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_APPROVE_CLAIM.getStatus(), 1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_APPROVE.getStatus()},
				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_APPROVE.getStatus(), 1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_CONFIRM.getStatus()},
				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_APPROVE.getStatus(), -1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_CHECK.getStatus()},
				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_APPROVE.getStatus(), -2, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_CREATED.getStatus()},

				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_CONFIRM.getStatus(), 1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_DELIVER.getStatus()},
				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_CONFIRM.getStatus(), -1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_CREATED.getStatus()},

				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_DELIVER.getStatus(), 1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_ACCEPT.getStatus()},
				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_DELIVER.getStatus(), -1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_ABORTED.getStatus()},

				// {EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_ACCEPT.getStatus(), 1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_ACCEPTING.getStatus()},
				// {EntrustmentStatusConstants.ENTRUSTMENT_STATUS_ACCEPTING.getStatus(), 1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_ACCEPTED.getStatus()},
				// {EntrustmentStatusConstants.ENTRUSTMENT_STATUS_ACCEPTING.getStatus(), -1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_CREATED.getStatus()},

				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_ACCEPT.getStatus(), 1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_ACCEPTED.getStatus()},
				{EntrustmentStatusConstants.ENTRUSTMENT_STATUS_WAITING_ACCEPT.getStatus(), -1, EntrustmentStatusConstants.ENTRUSTMENT_STATUS_CREATED.getStatus()},

		};
		for (int i = 0; i < processFlowMapper.length; i++) {
			if (processFlowMapper[i][0] == currentStatus) {
				// 当前状态就是它
				if (processFlowMapper[i][1] == opCode) {
					// 操作码找到了
					return processFlowMapper[i][2];
				}
			}
		}

		throw new RuntimeException("流程没有找到对应的下一状态");
	}
}
