export type PostLocaleCode = "zh" | "en" | "ja" | "ko" | "vi" | "id" | "ms";

export type PostType =
  | "image"
  | "video"
  | "music"
  | "ppt"
  | "pdf"
  | "link"
  | "text"
  | "archive";

export type PostTypeFilter = PostType | "all";
export type AttachmentKind = "image" | "video" | "document";

export type PostLocaleTexts = {
  /** Short display title for list/card surfaces. */
  title?: string;
  /** Full post body text. */
  text: string;
};

export type PostLocalizations = Record<PostLocaleCode, PostLocaleTexts>;

export type Attachment = {
  id: string;
  kind: AttachmentKind;
  url: string;
  mime: string;
  filename: string;
  sizeBytes: number;
  width?: number;
  height?: number;
  durationSec?: number;
  posterUrl?: string;
  thumbUrl?: string;
  thumbnailUrl?: string;
};

/**
 * Preview metadata for the first URL found in a post's text. See
 * `docs/link-preview.md` for the back-end contract.
 */
export type LinkPreview = {
  url: string;
  canonicalUrl: string;
  siteName: string;
  title: string;
  description: string;
  imageUrl?: string;
  imageWidth?: number;
  imageHeight?: number;
  favicon?: string;
  /** Hex color used for the left accent bar (e.g. "#12FF80"). */
  themeColor?: string;
};

export type Post = {
  id: string;
  postType?: PostType | string;
  categoryId: number;
  categorySlug: string;
  language: string;
  sourceLanguage?: string;
  /** Short display title for list/card surfaces. */
  title?: string;
  text?: string;
  localizations?: Partial<PostLocalizations>;
  attachments: Attachment[];
  isRecommended: boolean;
  publishedAt: string;
  updatedAt?: string;
  createdAt?: string;
  tags?: string[];
  /** Preview card for the first URL in `text`. At most one per post. */
  linkPreview?: LinkPreview;
};

export type PostListResponse = {
  items: Post[];
  nextCursor?: string;
};

export type PostDownloadResponse = {
  ok: true;
};

export type PostScope = { kind: "all" } | { kind: "category"; slug: string };
