"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthProviderRegistryService = void 0;
const common_1 = require("@nestjs/common");
const email_auth_provider_1 = require("../providers/email-auth.provider");
const phone_auth_provider_1 = require("../providers/phone-auth.provider");
const apple_auth_provider_1 = require("../providers/apple-auth.provider");
const google_auth_provider_1 = require("../providers/google-auth.provider");
const jwt_auth_provider_1 = require("../providers/jwt-auth.provider");
const facebook_auth_provider_1 = require("../providers/facebook-auth.provider");
const github_auth_provider_1 = require("../providers/github-auth.provider");
const auth_config_service_1 = require("./auth-config.service");
let AuthProviderRegistryService = class AuthProviderRegistryService {
    emailAuthProvider;
    phoneAuthProvider;
    jwtAuthProvider;
    googleAuthProvider;
    facebookAuthProvider;
    appleAuthProvider;
    githubAuthProvider;
    providers = new Map();
    options;
    constructor(emailAuthProvider, phoneAuthProvider, jwtAuthProvider, googleAuthProvider, facebookAuthProvider, appleAuthProvider, githubAuthProvider) {
        this.emailAuthProvider = emailAuthProvider;
        this.phoneAuthProvider = phoneAuthProvider;
        this.jwtAuthProvider = jwtAuthProvider;
        this.googleAuthProvider = googleAuthProvider;
        this.facebookAuthProvider = facebookAuthProvider;
        this.appleAuthProvider = appleAuthProvider;
        this.githubAuthProvider = githubAuthProvider;
        this.options = auth_config_service_1.AuthConfigService.getOptions();
        this.registerDefaultProviders();
    }
    registerDefaultProviders() {
        if (this.options.emailAuth?.enabled) {
            this.registerProvider(this.emailAuthProvider);
        }
        if (this.options.phoneAuth?.enabled) {
            this.registerProvider(this.phoneAuthProvider);
        }
        if (this.options.jwt) {
            this.registerProvider(this.jwtAuthProvider);
        }
        if (this.options.google) {
            this.registerProvider(this.googleAuthProvider);
        }
        if (this.options.facebook) {
            this.registerProvider(this.facebookAuthProvider);
        }
        if (this.options.apple) {
            this.registerProvider(this.appleAuthProvider);
        }
        if (this.options.github) {
            this.registerProvider(this.githubAuthProvider);
        }
        if (this.options.customAuthProviders && Array.isArray(this.options.customAuthProviders)) {
            for (const provider of this.options.customAuthProviders) {
                this.registerProvider(provider);
            }
        }
    }
    registerProvider(provider) {
        this.providers.set(provider.providerName, provider);
    }
    getProvider(providerName) {
        return this.providers.get(providerName);
    }
    getAllProviders() {
        return Array.from(this.providers.values());
    }
    getEnabledProviders() {
        return this.getAllProviders().filter(provider => 'enabled' in provider ? provider.enabled : true);
    }
    hasProvider(providerName) {
        return this.providers.has(providerName);
    }
};
exports.AuthProviderRegistryService = AuthProviderRegistryService;
exports.AuthProviderRegistryService = AuthProviderRegistryService = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [email_auth_provider_1.EmailAuthProvider,
        phone_auth_provider_1.PhoneAuthProvider,
        jwt_auth_provider_1.JwtAuthProvider,
        google_auth_provider_1.GoogleAuthProvider,
        facebook_auth_provider_1.FacebookAuthProvider,
        apple_auth_provider_1.AppleAuthProvider,
        github_auth_provider_1.GitHubAuthProvider])
], AuthProviderRegistryService);
//# sourceMappingURL=auth-provider-registry.service.js.map