// Channel Types
export interface Channel {
  id: string;
  name: string;
  url: string;
  group?: string;
  logo?: string;
  isMonitored: boolean;
  status: ChannelStatus;
  lastCheck?: number;
  lastError?: string;
  latency?: number;
}

export type ChannelStatus = 'online' | 'offline' | 'error' | 'unknown' | 'checking';

// IP Info Types
export interface IpInfo {
  ip: string;
  country: string;
  countryCode: string;
  city?: string;
  isp?: string;
  timezone?: string;
}

// Monitoring Types
export interface MonitoringResult {
  channelId: string;
  timestamp: number;
  status: ChannelStatus;
  latency?: number;
  httpStatus?: number;
  error?: string;
  errorType?: 'TIMEOUT' | 'CONNRESET' | 'CONNREFUSED' | 'HTTP_ERROR' | 'PARSE_ERROR' | 'UNKNOWN';
}

export interface PingResult {
  host: string;
  alive: boolean;
  time?: number;
  error?: string;
}

// Notification Types
export type NotificationType = 'windows' | 'telegram' | 'email';

export interface NotificationSettings {
  enabled: boolean;
  windows: {
    enabled: boolean;
  };
  telegram: {
    enabled: boolean;
    botToken: string;
    chatId: string;
  };
  email: {
    enabled: boolean;
    smtpHost: string;
    smtpPort: number;
    smtpUser: string;
    smtpPass: string;
    fromEmail: string;
    toEmail: string;
  };
  autoNotify: boolean;
  notifyOnPingFail: boolean;
  notifyOnStreamError: boolean;
  notifyOn404: boolean;
  notifyOnConnReset: boolean;
}

// Panel API Types (from MONITOR_API_GUIDE v1.1)
export interface PanelConfig {
  apiUrl: string;
  authToken: string;  // Now 64-char hex token from admin panel
  monitorId: string;
  enabled: boolean;
}

// Updated for API v1.1 - new response format from servers endpoint
export interface PanelIpInfo {
  ip_address: string;
  server_id: string;
  server_type: 'publisher' | 'monitor' | 'gateway';
  status: 'active' | 'inactive' | 'burned';
  active_users?: number;
  // Legacy field for backwards compatibility
  check_priority?: 'high' | 'normal' | 'low';
}

// Updated response format for API v1.1
export interface PanelIpPool {
  ips: PanelIpInfo[];
  timestamp: number;
  // Legacy fields for backwards compatibility
  active?: PanelIpInfo[];
  honeypot?: PanelIpInfo[];
}

// Updated for API v1.1 - monitor_id removed (extracted from Bearer token)
export interface BurnVote {
  ip_address: string;
  vote: 'burn' | 'ok' | 'abstain';
  evidence: BurnVoteEvidence;
}

// New evidence format for API v1.1
export interface BurnVoteEvidence {
  check_type: 'http_health' | 'tcp_connect' | 'ssl_verify' | 'dns_lookup';
  response_code: number;
  latency_ms: number;
  error_message: string | null;
  checked_at: string;  // ISO 8601 format
}

// New for API v1.1 - Heartbeat stats
export interface HeartbeatStats {
  active_checks: number;
  checks_last_minute: number;
  cpu_usage_percent?: number;
  memory_usage_mb?: number;
}

// Heartbeat response
export interface HeartbeatResponse {
  success: boolean;
  message: string;
}

// App Settings
export interface AppSettings {
  general: {
    startMinimized: boolean;
    minimizeToTray: boolean;
    autoStart: boolean;
    language: 'tr' | 'en';
  };
  monitoring: {
    pingInterval: number; // seconds
    streamCheckInterval: number; // seconds
    timeout: number; // ms
    retryCount: number;
  };
  notifications: NotificationSettings;
  panel: PanelConfig;
}

// IPC Channel Names
export const IPC_CHANNELS = {
  // IP Service
  GET_IP_INFO: 'ip:get-info',
  
  // Channel Management
  PARSE_M3U8: 'channel:parse-m3u8',
  GET_CHANNELS: 'channel:get-all',
  UPDATE_CHANNEL: 'channel:update',
  SET_MONITORED: 'channel:set-monitored',
  
  // Monitoring
  START_MONITORING: 'monitor:start',
  STOP_MONITORING: 'monitor:stop',
  GET_MONITORING_STATUS: 'monitor:status',
  MONITORING_UPDATE: 'monitor:update',
  
  // Ping
  PING_HOST: 'ping:host',
  
  // Notifications
  SEND_NOTIFICATION: 'notify:send',
  TEST_NOTIFICATION: 'notify:test',
  
  // Panel API
  PANEL_REGISTER: 'panel:register',  // Deprecated in v1.1
  PANEL_GET_IPS: 'panel:get-ips',
  PANEL_SEND_VOTE: 'panel:send-vote',
  PANEL_HEARTBEAT: 'panel:heartbeat',
  
  // Settings
  GET_SETTINGS: 'settings:get',
  SAVE_SETTINGS: 'settings:save',
  
  // Window
  MINIMIZE_TO_TRAY: 'window:minimize-tray',
} as const;

// Error Log Entry
export interface ErrorLogEntry {
  id: string;
  timestamp: number;
  channelName: string;
  channelId: string;
  errorType: string;
  errorMessage: string;
  httpStatus?: number;
  notified: boolean;
}

