/**
 * Shared types for the live news aggregator.
 *
 * `NewsItem` is the normalised shape we produce from any RSS or Atom feed,
 * regardless of the source's quirks. It is what the /news list page, the
 * /news/[id] detail page, and the refresh API all consume.
 */

export type NewsSource = {
  /** URL-safe slug used as sourceId and in filters. */
  id: string;
  /** Human-readable name shown in UI (pills, "Read at X"). */
  name: string;
  /** Fully-qualified feed URL (RSS 2.0 or Atom). */
  feedUrl: string;
  /** Publisher homepage, used as fallback outbound link. */
  homepageUrl: string;
};

export type NewsItem = {
  /** Deterministic base64url hash of sourceId + link, used as URL param. */
  id: string;
  sourceId: string;
  sourceName: string;
  title: string;
  /** Canonical outbound link back to the publisher article. */
  link: string;
  /** ISO-8601 publication timestamp. */
  pubDate: string;
  /** Extracted year for cheap filtering without re-parsing dates. */
  year: number;
  /** Plain-text excerpt, HTML-stripped and capped at ~220 chars. */
  excerpt: string;
  author?: string;
  /** Optional hero image URL extracted from feed enclosure/media tags or inline <img>. */
  imageUrl?: string;
};

/**
 * Raw shape emitted by the RSS adapter before we normalise into NewsItem.
 * Kept deliberately loose because feeds in the wild return all sorts of
 * nested weirdness.
 */
export type RawItem = {
  title: string;
  link: string;
  pubDate: string;
  description: string;
  author?: string;
  /** First image URL we could find in media tags, enclosures, or inline <img>. */
  imageUrl?: string;
};
