"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const JSONError_1 = require("./JSONError");
class RealmProblem extends JSONError_1.JSONError {
    get type() {
        return `https://realm.io/docs/object-server/problems/${this.path}`;
    }
    toJSON() {
        const json = super.toJSON();
        json.code = this.code;
        return json;
    }
}
exports.RealmProblem = RealmProblem;
class InvalidParameters extends RealmProblem {
    constructor(...parameters) {
        super();
        this.path = 'invalid-parameters';
        this.title = 'Your request parameters did not validate.';
        this.code = 601;
        this.invalidParams = (parameters || []).map((parameter) => {
            if (typeof parameter === 'string') {
                return {
                    name: parameter,
                    reason: `Invalid parameter '${parameter}'!`
                };
            }
            return parameter;
        });
    }
    get message() {
        return super.message + (this.invalidParams || []).map((param) => {
            return ` '${param.name}': ${param.reason}`;
        }).join('; ');
    }
    toJSON() {
        const json = super.toJSON();
        json.invalid_params = this.invalidParams;
        return json;
    }
}
exports.InvalidParameters = InvalidParameters;
class MissingParameters extends InvalidParameters {
    constructor(...parameters) {
        super(...(parameters || []).map((parameter) => {
            return {
                name: parameter,
                reason: `Missing parameter '${parameter}'!`,
            };
        }));
        this.path = 'missing-parameters';
        this.title = 'Your request did not validate because of missing parameters.';
        this.code = 602;
    }
}
exports.MissingParameters = MissingParameters;
class InvalidCredentials extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'invalid-credentials';
        this.title = 'The provided credentials are invalid or the user does not exist.';
        this.status = 401;
        this.code = 611;
    }
}
exports.InvalidCredentials = InvalidCredentials;
class UnknownAccount extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'unknown-account';
        this.title = 'The account does not exist.';
        this.status = 404;
        this.code = 612;
    }
}
exports.UnknownAccount = UnknownAccount;
class ExistingAccount extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'existing-account';
        this.title = 'The account cannot be registered as it exists already.';
        this.status = 400;
        this.code = 613;
    }
}
exports.ExistingAccount = ExistingAccount;
class AccessDenied extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'access-denied';
        this.title = 'The path is invalid or current user has no access.';
        this.status = 403;
        this.code = 614;
    }
}
exports.AccessDenied = AccessDenied;
class InvalidRealmType extends RealmProblem {
    constructor(expectedType, actualType) {
        super();
        this.path = 'invalid-realm-type';
        this.title = 'The type of the Realm file was invalid.';
        this.status = 400;
        this.code = 619;
        this.expectedType = expectedType;
        this.actualType = actualType;
    }
    get message() {
        return `${super.message} Expected ${this.expectedType} but got ${this.actualType}.`;
    }
}
exports.InvalidRealmType = InvalidRealmType;
class ExpiredRefreshToken extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'expired-refresh-token';
        this.title = 'The refresh token is expired.';
        this.status = 403;
        this.code = 615;
    }
}
exports.ExpiredRefreshToken = ExpiredRefreshToken;
class InvalidHost extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'invalid-host';
        this.title = 'The server is not authoritative for this URL.';
        this.status = 400;
        this.code = 616;
    }
}
exports.InvalidHost = InvalidHost;
class RealmNotFound extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'realm-not-found';
        this.title = 'The Realm could not be found';
        this.status = 404;
        this.code = 617;
    }
}
exports.RealmNotFound = RealmNotFound;
class UnknownUser extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'unknown-user';
        this.title = 'The user does not exist.';
        this.status = 404;
        this.code = 618;
    }
}
exports.UnknownUser = UnknownUser;
class ExpiredPermissionOffer extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'expired-permission-offer';
        this.title = 'The permission offer is expired.';
        this.status = 403;
        this.code = 701;
    }
}
exports.ExpiredPermissionOffer = ExpiredPermissionOffer;
class AmbiguousPermissionOfferToken extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'ambiguous-permission-offer';
        this.title = 'The token used in the PermissionOfferResponse does match more than a single PermissionOffer.';
        this.status = 403;
        this.code = 702;
    }
}
exports.AmbiguousPermissionOfferToken = AmbiguousPermissionOfferToken;
class FileMayNotBeShared extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'file-may-not-be-shared';
        this.title = 'The Realm file at the specified path is not available for shared access.';
        this.status = 403;
        this.code = 703;
    }
}
exports.FileMayNotBeShared = FileMayNotBeShared;
class ServerMisconfiguration extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'server-misconfiguration';
        this.title = 'The server was configured in a way that is inconsistent with its internal state.';
        this.status = 500;
        this.code = 801;
    }
}
exports.ServerMisconfiguration = ServerMisconfiguration;
class ServiceUnavailable extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'service-unavailable';
        this.title = 'The requested service is temporarily unavailable.';
        this.status = 503;
        this.code = 802;
    }
}
exports.ServiceUnavailable = ServiceUnavailable;
class NotSupported extends RealmProblem {
    constructor() {
        super(...arguments);
        this.path = 'not-enabled';
        this.title = 'The server was not configured to support the requested operation.';
        this.status = 501;
        this.code = 803;
    }
}
exports.NotSupported = NotSupported;
//# sourceMappingURL=RealmProblem.js.map