"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertAccountId = assertAccountId;
exports.parsePath = parsePath;
exports.verifyAccountId = verifyAccountId;
const global_logger_factory_1 = require("global-logger-factory");
const InternalServerError_1 = require("../../../../util/errors/InternalServerError");
const NotFoundHttpError_1 = require("../../../../util/errors/NotFoundHttpError");
const logger = (0, global_logger_factory_1.getLoggerFor)('AccountUtil');
/**
 * Asserts that the ID is defined. Throws a 404 otherwise.
 */
function assertAccountId(accountId) {
    if (!accountId) {
        throw new NotFoundHttpError_1.NotFoundHttpError();
    }
}
/**
 * Parses the given path with the given {@link InteractionRoute}.
 * This assumes this call will succeed and thus expects the path to have the correct format.
 * If not, a 500 error will be thrown.
 *
 * @param route - Route to parse with.
 * @param path - Path to parse.
 */
function parsePath(route, path) {
    const match = route.matchPath(path);
    if (!match) {
        logger.error(`Unable to parse path ${path}. This usually implies a server misconfiguration.`);
        throw new InternalServerError_1.InternalServerError(`Unable to parse path ${path}. This usually implies a server misconfiguration.`);
    }
    return match;
}
/**
 * Asserts that the two given IDs are identical.
 * To be used when a request tries to access a resource to ensure they're not accessing someone else's data.
 *
 * @param input - Input ID.
 * @param expected - Expected ID.
 */
function verifyAccountId(input, expected) {
    if (input !== expected) {
        throw new NotFoundHttpError_1.NotFoundHttpError();
    }
}
//# sourceMappingURL=AccountUtil.js.map