/**
 * TypeScript types for the blocklist management feature.
 */

// ---------------------------------------------------------------------------
// Sources
// ---------------------------------------------------------------------------

export interface BlocklistSource {
  id: number;
  name: string;
  url: string;
  enabled: boolean;
  created_at: string;
  updated_at: string;
}

export interface BlocklistSourceCreate {
  name: string;
  url: string;
  enabled: boolean;
}

export interface BlocklistSourceUpdate {
  name?: string;
  url?: string;
  enabled?: boolean;
}

export interface BlocklistListResponse {
  sources: BlocklistSource[];
}

// ---------------------------------------------------------------------------
// Import log
// ---------------------------------------------------------------------------

export interface ImportLogEntry {
  id: number;
  source_id: number | null;
  source_url: string;
  timestamp: string;
  ips_imported: number;
  ips_skipped: number;
  errors: string | null;
}

export interface ImportLogListResponse {
  items: ImportLogEntry[];
  total: number;
  page: number;
  page_size: number;
  total_pages: number;
}

// ---------------------------------------------------------------------------
// Schedule
// ---------------------------------------------------------------------------

export type ScheduleFrequency = "hourly" | "daily" | "weekly";

export interface ScheduleConfig {
  frequency: ScheduleFrequency;
  interval_hours: number;
  hour: number;
  minute: number;
  day_of_week: number;
}

export interface ScheduleInfo {
  config: ScheduleConfig;
  next_run_at: string | null;
  last_run_at: string | null;
  /** `true` if the most recent import had errors, `false` if clean, `null` if never run. */
  last_run_errors: boolean | null;
}

// ---------------------------------------------------------------------------
// Import results
// ---------------------------------------------------------------------------

export interface ImportSourceResult {
  source_id: number | null;
  source_url: string;
  ips_imported: number;
  ips_skipped: number;
  error: string | null;
}

export interface ImportRunResult {
  results: ImportSourceResult[];
  total_imported: number;
  total_skipped: number;
  errors_count: number;
}

// ---------------------------------------------------------------------------
// Preview
// ---------------------------------------------------------------------------

export interface PreviewResponse {
  entries: string[];
  total_lines: number;
  valid_count: number;
  skipped_count: number;
}
