/**
 * TypeScript interfaces mirroring the backend ban Pydantic models.
 *
 * `backend/app/models/ban.py` — dashboard dashboard sections.
 */

// ---------------------------------------------------------------------------
// Time-range selector
// ---------------------------------------------------------------------------

/** The four supported time-range presets for dashboard views. */
export type TimeRange = "24h" | "7d" | "30d" | "365d";

/**
 * Filter for the origin of a ban.
 *
 * - `"all"` — no filter, show all bans.
 * - `"blocklist"` — only bans from the blocklist-import jail.
 * - `"selfblock"` — only bans detected by fail2ban itself.
 */
export type BanOriginFilter = "all" | "blocklist" | "selfblock";

// ---------------------------------------------------------------------------
// Ban-list table item
// ---------------------------------------------------------------------------

/**
 * A single row in the dashboard ban-list table.
 *
 * Mirrors `DashboardBanItem` from `backend/app/models/ban.py`.
 */
export interface DashboardBanItem {
  /** Banned IP address. */
  ip: string;
  /** Jail that issued the ban. */
  jail: string;
  /** ISO 8601 UTC timestamp of the ban. */
  banned_at: string;
  /** First matched log line (context for the ban), or null. */
  service: string | null;
  /** ISO 3166-1 alpha-2 country code, or null if unknown. */
  country_code: string | null;
  /** Human-readable country name, or null if unknown. */
  country_name: string | null;
  /** Autonomous System Number string, e.g. "AS3320", or null. */
  asn: string | null;
  /** Organisation name associated with the IP, or null. */
  org: string | null;
  /** How many times this IP was banned. */
  ban_count: number;
  /** Whether this ban came from a blocklist import or fail2ban itself. */
  origin: "blocklist" | "selfblock";
}

/**
 * Paginated ban-list response from `GET /api/dashboard/bans`.
 *
 * Mirrors `DashboardBanListResponse` from `backend/app/models/ban.py`.
 */
export interface DashboardBanListResponse {
  /** Ban items for the current page. */
  items: DashboardBanItem[];
  /** Total number of bans in the selected time window. */
  total: number;
  /** Current 1-based page number. */
  page: number;
  /** Maximum items per page. */
  page_size: number;
}

// ---------------------------------------------------------------------------
// Ban trend
// ---------------------------------------------------------------------------

/**
 * A single time bucket in the ban trend series.
 *
 * Mirrors `BanTrendBucket` from `backend/app/models/ban.py`.
 */
export interface BanTrendBucket {
  /** ISO 8601 UTC start of the bucket. */
  timestamp: string;
  /** Number of bans that started in this bucket. */
  count: number;
}

/**
 * Response from `GET /api/dashboard/bans/trend`.
 *
 * Mirrors `BanTrendResponse` from `backend/app/models/ban.py`.
 */
export interface BanTrendResponse {
  /** Time-ordered list of ban-count buckets covering the full window. */
  buckets: BanTrendBucket[];
  /** Human-readable bucket size label, e.g. `"1h"`, `"6h"`, `"1d"`, `"7d"`. */
  bucket_size: string;
}

// ---------------------------------------------------------------------------
// Bans by jail
// ---------------------------------------------------------------------------

/**
 * A single jail entry in the bans-by-jail aggregation.
 *
 * Mirrors `JailBanCount` from `backend/app/models/ban.py`.
 */
export interface JailBanCount {
  /** Jail name. */
  jail: string;
  /** Number of bans recorded in this jail for the selected window. */
  count: number;
}

/**
 * Response from `GET /api/dashboard/bans/by-jail`.
 *
 * Mirrors `BansByJailResponse` from `backend/app/models/ban.py`.
 */
export interface BansByJailResponse {
  /** Jails ordered by ban count descending. */
  jails: JailBanCount[];
  /** Total ban count in the selected window. */
  total: number;
}
