/**
 * Data layer types shared by the public site.
 *
 * Originally derived from WordPress REST shapes; the v2 CMS (lib/cms.ts) maps
 * Prisma rows into the same `Post` / `WPTerm` / `WPAuthor` shape so existing
 * UI code keeps working unchanged.
 *
 * Note: Post.id, WPTerm.id and WPAuthor.id are typed as `string` because the
 * Prisma DB uses cuid identifiers. Components only use these as React keys or
 * for equality checks, so a string is sufficient.
 */

export interface WPMediaSize {
  source_url: string;
  width: number;
  height: number;
}

export interface WPMedia {
  id: number;
  source_url: string;
  alt_text: string;
  media_details?: {
    width?: number;
    height?: number;
    sizes?: Record<string, WPMediaSize>;
  };
}

export interface WPTerm {
  id: string;
  name: string;
  slug: string;
  link?: string;
  taxonomy?: string;
  parent?: string;
  count?: number;
  description?: string;
}

export interface WPAuthor {
  id: string;
  name: string;
  slug: string;
  description?: string;
  avatar_urls?: Record<string, string>;
  link?: string;
}

export interface WPPost {
  id: number;
  date: string;
  modified: string;
  slug: string;
  link: string;
  title: { rendered: string };
  excerpt: { rendered: string };
  content?: { rendered: string };
  author: number;
  featured_media: number;
  categories: number[];
  tags: number[];
  _embedded?: {
    author?: WPAuthor[];
    "wp:featuredmedia"?: WPMedia[];
    "wp:term"?: WPTerm[][];
  };
}

/** Normalized post we use throughout the UI */
export interface Post {
  id: string;
  slug: string;
  link: string;
  date: string;
  modified: string;
  title: string;
  excerpt: string;
  content?: string;
  readMinutes: number;
  noIndex?: boolean;
  author: { id: string; name: string; slug: string; avatar?: string; bio?: string };
  featured?: { url: string; alt: string; width?: number; height?: number };
  categories: WPTerm[];
  tags: WPTerm[];
}

export interface SeoMeta {
  title?: string;
  description?: string;
  canonical?: string;
  ogTitle?: string;
  ogDescription?: string;
  ogImage?: string;
  ogType?: string;
  twitterCard?: string;
  jsonLd?: string[];
  robots?: string;
}
