/**
 * Network-related data shapes for Onebox
 */

import type { IRuntimeObservation } from './runtime.js';

export type TNetworkTargetType = 'service' | 'registry' | 'platform';

export interface INetworkTarget {
  type: TNetworkTargetType;
  name: string;
  domain: string | null;
  targetHost: string;
  targetPort: number;
  status: string;
}

export interface INetworkStats {
  proxy: IRuntimeObservation & {
    httpPort: number;
    httpsPort: number;
    routes: number;
    certificates: number;
  };
  logReceiver: {
    running: boolean;
    port: number;
    clients: number;
    connections: number;
    sampleRate: number;
    recentLogsCount: number;
  };
}

export interface ITrafficStats {
  requestCount: number;
  errorCount: number;
  avgResponseTime: number;
  totalBytes: number;
  statusCounts: Record<string, number>;
  requestsPerMinute: number;
  errorRate: number;
}

export interface IProxyAccessLog {
  ts: number;
  request: {
    remote_ip: string;
    method: string;
    host: string;
    uri: string;
    proto: string;
  };
  status: number;
  duration: number;
  size: number;
}

export interface INetworkLogMessage {
  type: 'connected' | 'access_log' | 'filter_updated';
  clientId?: string;
  filter?: { domain?: string; sampleRate?: number };
  data?: IProxyAccessLog;
  timestamp: number;
}
