// 后端 API 契约类型，字段假设见 ui/README.md
export interface DownloadResourceSpec {
  slug: string;
  displayName: string;
  description?: string;
  attachmentName?: string;
  requireEmailVerify?: boolean;
  enabled?: boolean;
}

export interface DownloadResource {
  apiVersion?: string;
  kind?: string;
  metadata: {
    name: string;
    creationTimestamp?: string;
    [key: string]: unknown;
  };
  spec: DownloadResourceSpec;
  status?: {
    downloadCount?: number;
    [key: string]: unknown;
  };
  stats?: {
    downloaderCount?: number;
    referenceCount?: number;
    [key: string]: unknown;
  };
}

export interface DownloadResourceList {
  items: DownloadResource[];
  total: number;
}

export interface ProtectedLinkSpec {
  slug: string;
  displayName: string;
  description?: string;
  targetUrl?: string;
  requireEmailVerify?: boolean;
  enabled?: boolean;
}

export interface ProtectedLink {
  apiVersion?: string;
  kind?: string;
  metadata: {
    name: string;
    creationTimestamp?: string;
    [key: string]: unknown;
  };
  spec: ProtectedLinkSpec;
  status?: {
    visitCount?: number;
    [key: string]: unknown;
  };
  stats?: {
    visitorCount?: number;
    referenceCount?: number;
    [key: string]: unknown;
  };
}

export interface ProtectedLinkList {
  items: ProtectedLink[];
  total: number;
}

export interface DownloadRecord {
  metadata: {
    name: string;
    [key: string]: unknown;
  };
  spec: {
    resourceSlug: string;
    email?: string;
    ip?: string;
    userAgent?: string;
    downloadedAt?: string;
  };
}

export interface LinkVisitRecord {
  metadata: {
    name: string;
    [key: string]: unknown;
  };
  spec: {
    linkSlug: string;
    email?: string;
    ip?: string;
    userAgent?: string;
    visitedAt?: string;
  };
}

// 记录抽屉（下载/链接共用）所需的最小资源形状
export interface RecordSubject {
  metadata: {
    name: string;
    [key: string]: unknown;
  };
  spec: {
    displayName?: string;
    slug?: string;
    [key: string]: unknown;
  };
}

// Halo 标准 ListResult 结构
export interface ListResult<T> {
  items: T[];
  page: number;
  size: number;
  total: number;
  first?: boolean;
  last?: boolean;
  hasNext?: boolean;
  hasPrevious?: boolean;
  totalPages?: number;
}

export interface ReferenceInfo {
  postName: string;
  title: string;
  permalink: string;
  editorUrl: string;
}

// slug -> 引用文章列表
export type ReferencesMap = Record<string, ReferenceInfo[]>;
