"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.requireValidProtocolTransition = exports.Status = void 0;
var lodash_isequal_1 = __importDefault(require("lodash.isequal"));
var Status;
(function (Status) {
    Status[Status["True"] = 0] = "True";
    Status[Status["NeedToCheckApp"] = 1] = "NeedToCheckApp";
})(Status = exports.Status || (exports.Status = {}));
function requireValidProtocolTransition(fromState, toState) {
    _requireExtraImplicitChecks(fromState, toState);
    if (toState.isFinal) {
        _require(lodash_isequal_1.default(toState.outcome, fromState.outcome), 'InvalidTransitionError: Cannot move to a final state with a different default outcome');
    }
    else {
        _require(!fromState.isFinal, 'InvalidTransitionError: Cannot move from a final state to a non final state');
        if (toState.turnNum < 2 * toState.channel.participants.length) {
            _require(lodash_isequal_1.default(toState.outcome, fromState.outcome), 'InvalidTransitionError: Cannot change the default outcome during setup phase');
            _require(toState.appData == fromState.appData, 'InvalidTransitionError: Cannot change the appData during setup phase');
        }
        else {
            return Status.NeedToCheckApp;
        }
    }
    return Status.True;
}
exports.requireValidProtocolTransition = requireValidProtocolTransition;
function _requireExtraImplicitChecks(fromState, toState) {
    _require(toState.turnNum == fromState.turnNum + 1, 'turnNum must increment by one');
    _require(toState.channel.chainId == fromState.channel.chainId, 'chainId must not change');
    _require(lodash_isequal_1.default(toState.channel.participants, fromState.channel.participants), 'participants must not change');
    _require(toState.channel.channelNonce == fromState.channel.channelNonce, 'channelNonce must not change');
    _require(toState.appDefinition == fromState.appDefinition, 'appDefinition must not change');
    _require(toState.challengeDuration == fromState.challengeDuration, 'challengeDuration must not change');
}
function _require(expression, errorString) {
    if (!expression)
        throw Error(errorString);
}
//# sourceMappingURL=valid-transition.js.map