/**
 * Network Collector
 * Phase 3: Origin class, public IP masked, latency, geo
 * Runs slower (expensive checks)
 */
import { getSystemState } from '../system-state.js';
/**
 * Collect network context
 * Expensive checks - should run slower (10-30s)
 */
export async function collectNetwork(appState) {
    try {
        let systemState;
        try {
            systemState = getSystemState(appState, false);
        }
        catch {
            systemState = null;
        }
        if (!systemState) {
            return {
                status: 'UNAVAILABLE',
                asOf: Date.now(),
                source: 'collector_network',
                staleAfterMs: 30000, // Expensive - refresh every 30s
                reasonCode: 'NO_SYSTEM_STATE',
                message: 'System state not available',
                action: 'system status',
            };
        }
        const network = systemState.networkContext;
        // Mask public IP (v1: return HIDDEN)
        const publicIpMasked = "HIDDEN";
        // Latency (simplified - would ping gateway)
        const latencyMs = "UNKNOWN";
        const data = {
            originRegion: network.operatorOrigin.region || "UNKNOWN",
            originClass: network.operatorOrigin.networkType,
            gatewayRegion: network.targetInfrastructure.gatewayRegion || "UNKNOWN",
            dbRegion: network.targetInfrastructure.databaseRegion || "NONE",
            latencyMs,
            latencyClass: network.targetInfrastructure.latencyClass,
            publicIpMasked,
        };
        // Phase 9: Determine status
        const now = Date.now();
        let status = 'LIVE';
        let reasonCode;
        let message;
        let action;
        if (!appState.gatewayConnected) {
            status = 'UNAVAILABLE';
            reasonCode = 'GATEWAY_NOT_CONNECTED';
            message = 'Gateway not connected';
            action = 'system connect';
        }
        else {
            status = 'LIVE';
        }
        return {
            status,
            asOf: now,
            data,
            source: 'collector_network',
            staleAfterMs: 30000, // Expensive - refresh every 30s
            reasonCode,
            message,
            action,
        };
    }
    catch (error) {
        return {
            status: 'UNAVAILABLE',
            asOf: Date.now(),
            source: 'collector_network',
            staleAfterMs: 30000,
            reasonCode: 'COLLECTION_ERROR',
            message: error.message || 'Unknown error',
            action: 'system status',
        };
    }
}
//# sourceMappingURL=collector_network.js.map