'use strict';

exports.Flaw = void 0;
(function (Flaw) {
    function is(value) {
        return (typeof value == "object" &&
            (value.property == undefined || typeof value.property == "string") &&
            typeof value.type == "string" &&
            (value.flaws == undefined || (Array.isArray(value.flaws) && value.flaws.every(Flaw.is))) &&
            (value.condition == undefined || typeof value.condition == "string"));
    }
    Flaw.is = is;
})(exports.Flaw || (exports.Flaw = {}));

var Result;
(function (Result) {
    function is(value) {
        return (typeof value == "object" &&
            typeof value.status == "number" &&
            (value.header == undefined ||
                (typeof value.header == "object" && (value.header.eTag == undefined || typeof value.header.eTag == "string"))));
    }
    Result.is = is;
    function hasBody(value) {
        return typeof value == "object" && typeof value.status == "number" && value.body != undefined && value.body != null;
    }
    Result.hasBody = hasBody;
    function getBody(value, fallback) {
        return hasBody(value) ? value.body : fallback;
    }
    Result.getBody = getBody;
})(Result || (Result = {}));

function flawedContent(content, error) {
    return { status: 400, type: "flawed content", content, error };
}
exports.FlawedContent = void 0;
(function (FlawedContent) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 400 &&
            value.type == "flawed content" &&
            exports.Flaw.is(value.content) &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    FlawedContent.is = is;
})(exports.FlawedContent || (exports.FlawedContent = {}));

function invalidContent(type, description, details, error) {
    return { status: 400, type: "invalid content", content: { type, description, details }, error };
}
var InvalidContent;
(function (InvalidContent) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 400 &&
            value.type == "invalid content" &&
            (value.content == undefined ||
                (typeof value.content == "object" &&
                    typeof value.content.type == "string" &&
                    typeof value.content.description == "string")) &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    InvalidContent.is = is;
})(InvalidContent || (InvalidContent = {}));

function invalidPathArgument(pattern, name, type, description, error) {
    return { status: 400, type: "invalid path argument", pattern, argument: { name, type, description }, error };
}
var InvalidPathArgument;
(function (InvalidPathArgument) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 400 &&
            value.type == "invalid path argument" &&
            typeof value.pattern == "string" &&
            typeof value.argument == "object" &&
            typeof value.argument.name == "string" &&
            typeof value.argument.type == "string" &&
            typeof value.argument.description == "string" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    InvalidPathArgument.is = is;
})(InvalidPathArgument || (InvalidPathArgument = {}));

function invalidQueryArgument(name, type, description, error) {
    return { status: 400, type: "invalid query argument", argument: { name, type, description }, error };
}
var InvalidQueryArgument;
(function (InvalidQueryArgument) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 400 &&
            value.type == "invalid query argument" &&
            typeof value.argument == "object" &&
            typeof value.argument.name == "string" &&
            typeof value.argument.type == "string" &&
            typeof value.argument.description == "string" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    InvalidQueryArgument.is = is;
})(InvalidQueryArgument || (InvalidQueryArgument = {}));

function malformedContent(property, type, description, details, error) {
    return { status: 400, type: "malformed content", content: { property, type, description, details }, error };
}
var MalformedContent;
(function (MalformedContent) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 400 &&
            value.type == "malformed content" &&
            typeof value.content == "object" &&
            typeof value.content.property == "string" &&
            typeof value.content.type == "string" &&
            typeof value.content.description == "string" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    MalformedContent.is = is;
})(MalformedContent || (MalformedContent = {}));

var MethodNotAllowed;
(function (MethodNotAllowed) {
    MethodNotAllowed.methods = ["GET", "POST", "DELETE", "HEAD", "PATCH", "PUT", "OPTIONS", "TRACE", "CONNECT"];
    function is(value) {
        return (typeof value == "object" &&
            value.status == 405 &&
            value.type == "method not allowed" &&
            typeof value.header == "object" &&
            Array.isArray(value.header.allow) &&
            value.header.allow.every((m) => MethodNotAllowed.methods.includes(m)) &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    MethodNotAllowed.is = is;
})(MethodNotAllowed || (MethodNotAllowed = {}));

var MissingProperty;
(function (MissingProperty) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 400 &&
            value.type == "missing property" &&
            typeof value.content == "object" &&
            typeof value.content.property == "string" &&
            typeof value.content.type == "string" &&
            Object.values(value.content).every(v => v == undefined || typeof v == "string") &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    MissingProperty.is = is;
})(MissingProperty || (MissingProperty = {}));

var MissingQueryArgument;
(function (MissingQueryArgument) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 400 &&
            value.type == "missing query argument" &&
            typeof value.argument == "object" &&
            typeof value.argument.name == "string" &&
            typeof value.argument.type == "string" &&
            typeof value.argument.description == "string" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    MissingQueryArgument.is = is;
})(MissingQueryArgument || (MissingQueryArgument = {}));

var NotFound;
(function (NotFound) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 404 &&
            value.type == "not found" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    NotFound.is = is;
})(NotFound || (NotFound = {}));

function unauthorized(error) {
    return { status: 401, type: "not authorized", error };
}
var Unauthorized;
(function (Unauthorized) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 401 &&
            value.type == "not authorized" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    Unauthorized.is = is;
})(Unauthorized || (Unauthorized = {}));

exports.Error = void 0;
(function (Error) {
    function is(value) {
        return (typeof value == "object" &&
            typeof value.type == "string" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value) &&
            value.status >= 400);
    }
    Error.is = is;
})(exports.Error || (exports.Error = {}));

function found(location) {
    return { status: 302, location };
}
(function (found) {
    function is(value) {
        return Result.is(value) && value.status == 302;
    }
    found.is = is;
})(found || (found = {}));

function notModified(eTag) {
    return { status: 304, header: { eTag: eTag } };
}
(function (notModified) {
    function is(value) {
        return (typeof value == "object" &&
            Result.is(value) &&
            value.status == 304 &&
            typeof value.header == "object" &&
            typeof value.header.eTag == "string");
    }
    notModified.is = is;
})(notModified || (notModified = {}));

function permanent(location) {
    return { status: 301, location };
}
(function (permanent) {
    function is(value) {
        return Result.is(value) && value.status == 301;
    }
    permanent.is = is;
})(permanent || (permanent = {}));

function backendFailure(backend, details, reference, error) {
    if (backend != "string" && details == undefined && reference == undefined && error == undefined) {
        details = backend;
        backend = "unknown";
    }
    return { status: 502, type: "backend failure", backend, details, reference, error };
}
var BackendFailure;
(function (BackendFailure) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 502 &&
            value.type == "backend failure" &&
            typeof value.backend == "string" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    BackendFailure.is = is;
})(BackendFailure || (BackendFailure = {}));

var BackendTimeout;
(function (BackendTimeout) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 504 &&
            value.type == "backend timeout" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    BackendTimeout.is = is;
})(BackendTimeout || (BackendTimeout = {}));

function databaseFailure(details, error) {
    return { status: 502, type: "database failure", details, error };
}
var DatabaseFailure;
(function (DatabaseFailure) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 502 &&
            value.type == "database failure" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    DatabaseFailure.is = is;
})(DatabaseFailure || (DatabaseFailure = {}));

var DatabaseTimeout;
(function (DatabaseTimeout) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 504 &&
            value.type == "database timeout" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    DatabaseTimeout.is = is;
})(DatabaseTimeout || (DatabaseTimeout = {}));

function misconfigured(key, description, error) {
    return { status: 503, type: "missing configuration", key, description, error };
}
var Misconfigured;
(function (Misconfigured) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 503 &&
            value.type == "missing configuration" &&
            typeof value.key == "string" &&
            typeof value.description == "string" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    Misconfigured.is = is;
})(Misconfigured || (Misconfigured = {}));

function unavailable(error) {
    return { status: 503, type: "service unavailable", error };
}
var Unavailable;
(function (Unavailable) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 503 &&
            value.type == "service unavailable" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    Unavailable.is = is;
})(Unavailable || (Unavailable = {}));

function unknown(details, error) {
    return { status: 500, type: "unknown error", details, error };
}
var Unknown;
(function (Unknown) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 500 &&
            value.type == "unknown error" &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    Unknown.is = is;
})(Unknown || (Unknown = {}));

function created(body) {
    return { status: 201, body };
}
(function (created) {
    function is(value) {
        return typeof value == "object" && value.body && Result.is(value) && value.status == 201;
    }
    created.is = is;
})(created || (created = {}));

function noContent() {
    return { status: 204 };
}
(function (noContent) {
    function is(value) {
        return Result.is(value) && value.status == 204;
    }
    noContent.is = is;
})(noContent || (noContent = {}));

function ok(body, eTag) {
    return { status: 200, body, header: { eTag } };
}
(function (ok) {
    function is(value) {
        return typeof value == "object" && value.body && Result.is(value) && value.status == 200;
    }
    ok.is = is;
})(ok || (ok = {}));

exports.backendFailure = backendFailure;
exports.databaseFailure = databaseFailure;
exports.flawedContent = flawedContent;
exports.invalidContent = invalidContent;
exports.invalidPathArgument = invalidPathArgument;
exports.invalidQueryArgument = invalidQueryArgument;
exports.malformedContent = malformedContent;
exports.misconfigured = misconfigured;
exports.unauthorized = unauthorized;
exports.unavailable = unavailable;
exports.unknown = unknown;
