/**
 * Trust Oracle - Vendor Trust Scoring and Third-Party Risk Management
 *
 * A comprehensive service for assessing, monitoring, and managing
 * third-party vendor risk within the Vorion security platform.
 *
 * @module trust-oracle
 */
// ============================================================================
// Main Oracle Service
// ============================================================================
export { TrustOracleService, createTrustOracle, getDefaultTrustOracleOptions, TrustOracleError, } from './oracle';
// ============================================================================
// Vendor Registry
// ============================================================================
export { VendorRegistry, VendorRegistryError, } from './vendor-registry';
// ============================================================================
// Risk Scoring Engine
// ============================================================================
export { RiskScorer, createRiskScorer, } from './risk-scorer';
// ============================================================================
// Continuous Monitoring
// ============================================================================
export { ContinuousMonitoringService, createContinuousMonitoringService, getDefaultPollingIntervals, MonitoringError, } from './continuous-monitoring';
// ============================================================================
// Data Sources
// ============================================================================
export { DataSourceManager, DataSource, DataSourceError, createDataSourceManager, getDefaultDataSourceConfig, } from './data-sources';
// ============================================================================
// Alert Management
// ============================================================================
export { AlertManager, createAlertManager, getDefaultEscalationPolicies, AlertError, } from './alerts';
// ============================================================================
// Reporting
// ============================================================================
export { ReportingService, createReportingService, ReportingError, } from './reporting';
// ============================================================================
// REST API
// ============================================================================
export { TrustOracleApiRouter, createTrustOracleApi, generateOpenApiSpec, } from './api';
// ============================================================================
// Module Info
// ============================================================================
export const MODULE_INFO = {
    name: 'trust-oracle',
    version: '1.0.0',
    description: 'Vendor Trust Scoring and Third-Party Risk Management',
    author: 'Vorion Security Platform',
    license: 'MIT',
};
// ============================================================================
// Quick Start Factory
// ============================================================================
import { TrustOracleService } from './oracle';
import { VendorRegistry } from './vendor-registry';
import { RiskScorer } from './risk-scorer';
import { DataSourceManager, getDefaultDataSourceConfig } from './data-sources';
import { ContinuousMonitoringService, getDefaultPollingIntervals } from './continuous-monitoring';
import { AlertManager, getDefaultEscalationPolicies } from './alerts';
import { ReportingService } from './reporting';
import { TrustOracleApiRouter } from './api';
/**
 * Creates a fully configured Trust Oracle system with all components
 */
export function createTrustOracleSystem(config) {
    // Create data source manager
    const dataSourceManager = new DataSourceManager(config.dataSourceConfig || getDefaultDataSourceConfig());
    // Create risk scorer
    const riskScorer = new RiskScorer(config.riskScorerConfig);
    // Create vendor registry
    const vendorRegistry = new VendorRegistry({
        storage: config.vendorStorage,
        auditLogger: config.auditLogger,
        notificationService: config.notificationService,
        workflowEngine: config.workflowEngine,
    });
    // Create alert manager
    const alertManager = new AlertManager({
        storage: config.alertStorage,
        notificationChannels: [],
        escalationPolicies: config.alertEscalationPolicies || getDefaultEscalationPolicies(),
        deduplicationWindow: 3600000, // 1 hour
        autoResolveEnabled: true,
    });
    // Create alert dispatcher for monitoring service
    const alertDispatcher = {
        async dispatchIfNeeded(event) {
            if (event.severity === 'critical' || event.severity === 'error') {
                const vendor = await vendorRegistry.getVendor(event.vendorId);
                await alertManager.createAlertFromHealthEvent(event, vendor);
            }
        },
    };
    // Create monitoring service
    const monitoringService = new ContinuousMonitoringService({
        dataSourceManager,
        storage: config.monitoringStorage,
        alertDispatcher,
        defaultPollingIntervals: getDefaultPollingIntervals(),
        enabledChecks: [
            'security_posture',
            'certificates',
            'dns',
            'breaches',
            'dark_web',
            'sanctions',
        ],
    });
    // Trust oracle placeholder for lazy initialization
    let trustOracleInstance = null;
    const getTrustOracle = () => {
        if (!trustOracleInstance) {
            throw new Error('Trust oracle not initialized');
        }
        return trustOracleInstance;
    };
    // Create reporting service with lazy trust oracle access
    const reportingService = new ReportingService({
        storage: config.reportStorage,
        auditLogger: config.auditLogger,
        templateEngine: config.templateEngine,
        exportService: config.exportService,
        dataProviders: {
            getVendorInfo: (vendorId) => vendorRegistry.getVendor(vendorId),
            getTrustScore: (vendorId) => getTrustOracle().getVendorTrustScore(vendorId),
            getTrustScoreHistory: (vendorId, days) => getTrustOracle().getTrustScoreHistory(vendorId, days),
            getRiskAssessment: async (vendorId) => {
                const vendor = await vendorRegistry.getVendor(vendorId);
                return getTrustOracle().assessThirdPartyRisk(vendor);
            },
            getCertifications: (vendorId) => vendorRegistry.getVendorCertifications(vendorId),
            getContracts: (vendorId) => vendorRegistry.getVendorContracts(vendorId),
            getAlerts: (vendorId, days) => alertManager.getVendorAlerts(vendorId, {
                startDate: new Date(Date.now() - days * 24 * 60 * 60 * 1000),
            }),
            getHealthEvents: (vendorId, days) => monitoringService.getHealthEvents(vendorId, {
                startDate: new Date(Date.now() - days * 24 * 60 * 60 * 1000),
            }),
        },
    });
    // Create cache implementation
    const cacheStore = new Map();
    const cache = {
        get(key) {
            const entry = cacheStore.get(key);
            if (!entry || Date.now() > entry.expiresAt) {
                cacheStore.delete(key);
                return null;
            }
            return entry.score;
        },
        set(key, score, ttlSeconds) {
            cacheStore.set(key, {
                score,
                expiresAt: Date.now() + ttlSeconds * 1000,
            });
        },
        invalidate(key) {
            cacheStore.delete(key);
        },
        clear() {
            cacheStore.clear();
        },
    };
    // Create trust oracle
    trustOracleInstance = new TrustOracleService({
        vendorRegistry,
        riskScorer,
        dataSourceManager,
        monitoringService,
        alertManager,
        reportingService,
        storage: config.trustOracleStorage,
        cache,
        options: {
            cacheEnabled: true,
            cacheTTLSeconds: 3600,
            autoMonitoringEnabled: true,
            alertOnScoreDegradation: true,
            degradationThreshold: 10,
            parallelDataFetching: true,
        },
    });
    const trustOracle = trustOracleInstance;
    // Create API router
    const apiRouter = new TrustOracleApiRouter({
        trustOracle,
        vendorRegistry,
        alertManager,
        reportingService,
        monitoringService,
        authMiddleware: config.authMiddleware,
        rateLimiter: config.rateLimiter,
    });
    return {
        trustOracle,
        vendorRegistry,
        riskScorer,
        dataSourceManager,
        monitoringService,
        alertManager,
        reportingService,
        apiRouter,
    };
}
//# sourceMappingURL=index.js.map