// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0
import "./_dnt.polyfills.js";
import { RawAuth } from "./typegraph.js";
import { wit_utils } from "./wit.js";
export function noProfiler() {
    return { profiler: "none" };
}
export function defaultProfiler() {
    return { profiler: "default" };
}
// deno-lint-ignore no-explicit-any
export function extendedProfiler(extension) {
    return { profiler: "extended", extension };
}
export function customProfiler(func) {
    return { profiler: "custom", id: func._id };
}
export class Auth {
    static jwt(name, format, algorithmParams) {
        if (!algorithmParams) {
            algorithmParams = {};
        }
        const authData = [
            ["format", JSON.stringify(format)],
            ["algorithm", JSON.stringify(algorithmParams)],
        ];
        return {
            name,
            authData,
            protocol: { tag: "jwt" },
        };
    }
    static hmac256(name) {
        return Auth.jwt(name, "raw", {
            name: "HMAC",
            hash: { name: "SHA-256" },
        });
    }
    static basic(users) {
        const authData = [["users", JSON.stringify(users)]];
        return {
            name: "basic",
            protocol: { tag: "basic" },
            authData,
        };
    }
    static stdOauth2(provider, scopes, profiler) {
        switch (profiler.profiler) {
            case "none":
                return new RawAuth(wit_utils.oauth2WithoutProfiler(provider, scopes));
            case "extended":
                return new RawAuth(wit_utils.oauth2WithExtendedProfiler(provider, scopes, JSON.stringify(profiler.extension)));
            case "custom":
                return new RawAuth(wit_utils.oauth2WithCustomProfiler(provider, scopes, profiler.id));
            default:
                return new RawAuth(wit_utils.oauth2(provider, scopes));
        }
    }
    static oauth2Digitalocean(scopes, profiler) {
        return Auth.stdOauth2("digitalocean", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Discord(scopes, profiler) {
        return Auth.stdOauth2("discord", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Dropbox(scopes, profiler) {
        return Auth.stdOauth2("dropbox", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Facebook(scopes, profiler) {
        return Auth.stdOauth2("facebook", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Github(scopes, profiler) {
        return Auth.stdOauth2("github", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Gitlab(scopes, profiler) {
        return Auth.stdOauth2("gitlab", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Google(scopes, profiler) {
        return Auth.stdOauth2("google", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Instagram(scopes, profiler) {
        return Auth.stdOauth2("instagram", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Linkedin(scopes, profiler) {
        return Auth.stdOauth2("linkedin", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Microsoft(scopes, profiler) {
        return Auth.stdOauth2("microsoft", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Reddit(scopes, profiler) {
        return Auth.stdOauth2("reddit", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Slack(scopes, profiler) {
        return Auth.stdOauth2("slack", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Stackexchange(scopes, profiler) {
        return Auth.stdOauth2("stackexchange", scopes, profiler ?? defaultProfiler());
    }
    static oauth2Twitter(scopes, profiler) {
        return Auth.stdOauth2("twitter", scopes, profiler ?? defaultProfiler());
    }
}
