"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.storageProvider = void 0;
const logger_1 = require("../config/logger");
/**
 * Singleton registry para o storage provider ativo.
 * O plugin UnifiedStorageProvider se registra aqui durante o activate().
 * O plugin uploads chama uploadFile() para enviar ao storage registrado.
 */
class StorageProviderRegistry {
    constructor() {
        this.provider = null;
        this.healthy = false;
    }
    register(provider) {
        this.provider = provider;
        logger_1.logger.info('[StorageProvider] Provider registrado');
    }
    isRegistered() {
        return this.provider !== null;
    }
    isHealthy() {
        return this.healthy;
    }
    async uploadFile(payload) {
        if (!this.provider) {
            throw new Error('Nenhum storage provider registrado. Ative o plugin UnifiedStorageProvider.');
        }
        return this.provider.upload(payload);
    }
    /** Atualiza o status de saúde — chamado periodicamente pelo UnifiedStorageProvider */
    async updateHealth() {
        if (!this.provider) {
            this.healthy = false;
            return;
        }
        try {
            this.healthy = await this.provider.checkHealth();
        }
        catch {
            this.healthy = false;
        }
    }
    unregister() {
        this.provider = null;
        this.healthy = false;
        logger_1.logger.info('[StorageProvider] Provider removido');
    }
}
exports.storageProvider = new StorageProviderRegistry();
