import { d as decode, e as encode, T as TextEncoder } from './Token-ba2c5d5c.js';
import { T as TextDecoder } from './TextDecoder-357ac2ce.js';

var Flaw;
(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;
})(Flaw || (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 = {}));

var FlawedContent;
(function (FlawedContent) {
    function is(value) {
        return (typeof value == "object" &&
            value.status == 400 &&
            value.type == "flawed content" &&
            Flaw.is(value.content) &&
            (value.error == undefined || typeof value.error == "string") &&
            Result.is(value));
    }
    FlawedContent.is = is;
})(FlawedContent || (FlawedContent = {}));

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 = {}));

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 = {}));

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 = {}));

function notFound(error) {
    return { status: 404, type: "not found", error };
}
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 = {}));

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 = {}));

var Error;
(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;
})(Error || (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 = {}));

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 = {}));

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 = {}));

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 = {}));

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 = {}));

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 = {}));

var Credentials;
(function (Credentials) {
    function is(value) {
        return (typeof value == "object" &&
            typeof value.user == "string" &&
            value.user != "" &&
            (value.password == undefined || typeof value.password == "string"));
    }
    Credentials.is = is;
    function fromBasic(login) {
        let result;
        if (login && login.substr(0, 6).toLowerCase() == "basic ") {
            const data = new TextDecoder().decode(decode(login.substr(6), "standard")).split(":");
            result =
                data.length < 3 && data.length > 0
                    ? { user: data[0], password: data.length > 1 ? data[1] : undefined }
                    : undefined;
        }
        return result;
    }
    Credentials.fromBasic = fromBasic;
    function toBasic(credentials) {
        return `Basic ${encode(new TextEncoder().encode(credentials.user + ":" + credentials.password), "standard", "=")}`;
    }
    Credentials.toBasic = toBasic;
})(Credentials || (Credentials = {}));

export { Credentials as C, Error as E, Flaw as F, malformedContent as m, notFound as n };
