"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);
};
var ProviderFactory_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProviderFactory = void 0;
const common_1 = require("@nestjs/common");
const config_service_1 = require("../../common/config/config.service");
const state_machines_1 = require("../../common/constants/state-machines");
const mikrotik_provider_1 = require("./mikrotik.provider");
const radius_provider_1 = require("./radius.provider");
const freeradius_provider_1 = require("./freeradius.provider");
const unifi_provider_1 = require("./unifi.provider");
const openwrt_provider_1 = require("./openwrt.provider");
const mock_provider_1 = require("./mock.provider");
let ProviderFactory = ProviderFactory_1 = class ProviderFactory {
    constructor(configService, mikrotikProvider, radiusProvider, freeRadiusProvider, unifiProvider, openWrtProvider, mockProvider) {
        this.configService = configService;
        this.mikrotikProvider = mikrotikProvider;
        this.radiusProvider = radiusProvider;
        this.freeRadiusProvider = freeRadiusProvider;
        this.unifiProvider = unifiProvider;
        this.openWrtProvider = openWrtProvider;
        this.mockProvider = mockProvider;
        this.logger = new common_1.Logger(ProviderFactory_1.name);
        this.providers = new Map();
        this.providers.set(state_machines_1.ROUTER_PLATFORMS.MIKROTIK, this.mikrotikProvider);
        this.providers.set(state_machines_1.ROUTER_PLATFORMS.RADIUS, this.radiusProvider);
        this.providers.set(state_machines_1.ROUTER_PLATFORMS.FREERADIUS, this.freeRadiusProvider);
        this.providers.set(state_machines_1.ROUTER_PLATFORMS.UNIFI, this.unifiProvider);
        this.providers.set(state_machines_1.ROUTER_PLATFORMS.OPENWRT, this.openWrtProvider);
        const nodeEnv = this.configService.get('NODE_ENV', 'development');
        const demoMode = this.configService.get('DEMO_MODE', 'false');
        if (nodeEnv === 'development' && demoMode === 'true') {
            this.logger.warn('Running in DEMO mode - all router operations will use MockProvider');
        }
    }
    isDemoMode() {
        const nodeEnv = this.configService.get('NODE_ENV', 'development');
        const demoMode = this.configService.get('DEMO_MODE', 'false');
        return nodeEnv === 'development' && demoMode === 'true';
    }
    getProvider(platform) {
        if (this.isDemoMode()) {
            this.logger.debug(`Demo mode: returning MockProvider for platform "${platform}"`);
            return this.mockProvider;
        }
        const provider = this.providers.get(platform);
        if (!provider) {
            this.logger.warn(`No provider found for platform "${platform}", falling back to MockProvider`);
            return this.mockProvider;
        }
        return provider;
    }
    getAllProviders() {
        const result = [];
        for (const [platform, provider] of this.providers.entries()) {
            result.push({ platform, provider });
        }
        return result;
    }
};
exports.ProviderFactory = ProviderFactory;
exports.ProviderFactory = ProviderFactory = ProviderFactory_1 = __decorate([
    (0, common_1.Injectable)(),
    __metadata("design:paramtypes", [config_service_1.ConfigService,
        mikrotik_provider_1.MikroTikProvider,
        radius_provider_1.RadiusProvider,
        freeradius_provider_1.FreeRadiusProvider,
        unifi_provider_1.UnifiProvider,
        openwrt_provider_1.OpenWrtProvider,
        mock_provider_1.MockProvider])
], ProviderFactory);
