import { EVirtualState } from './state-machine'; import { LogAndError } from "@birbal/common-utilities/dist/error"; export class VirtualStatusCheck { static async checkForStatusChange(to: EVirtualState, from?: EVirtualState) { switch (to) { case EVirtualState.PENDING: if (!from) return; throw new LogAndError("State change not allowed: From " + from + " to " + to); case EVirtualState.SUBMITTED: if (from === EVirtualState.PENDING) return; throw new LogAndError("State change not allowed: From " + from + " to " + to); case EVirtualState.REJECTED: if (from === EVirtualState.SUBMITTED) return; throw new LogAndError("State change not allowed: From " + from + " to " + to); case EVirtualState.REMOVED: if (from === EVirtualState.SUBMITTED) return; throw new LogAndError("State change not allowed: From " + from + " to " + to); case EVirtualState.APPROVED: if (from === EVirtualState.SUBMITTED || from === EVirtualState.REVOKED || from === EVirtualState.EXPIRED) return; throw new LogAndError("State change not allowed: From " + from + " to " + to); case EVirtualState.EXPIRED: if (from === EVirtualState.APPROVED) return; throw new LogAndError("State change not allowed: From " + from + " to " + to); case EVirtualState.REVOKED: if (from === EVirtualState.APPROVED) return; throw new LogAndError("State change not allowed: From " + from + " to " + to); default: throw new LogAndError("Invalid state request"); } } }