import type { PageDocument } from './page.js';
import type { VaryDimension } from './render-mode.js';

export interface RenderCapabilities {
  staticRender: boolean;
  ssr: boolean;
  ssrIslands: boolean;
  clientIslands: boolean;
  fragmentRender: boolean;
}

export interface GradialRenderer {
  renderPage(request: RenderPageRequest): Promise<RenderPageResult>;
  renderFragment?(request: RenderFragmentRequest): Promise<RenderResult>;
  renderIsland?(request: RenderIslandRequest): Promise<RenderResult>;
}

export interface RenderPageRequest {
  page: PageDocument;
  requestContext?: RequestContext;
  release: ReleaseContext;
}

export interface RequestContext {
  url: string;
  method: string;
  headers: Record<string, string>;
  cookies: Record<string, string>;
  geo?: GeoContext;
}

export interface GeoContext {
  country?: string;
  region?: string;
  city?: string;
}

export interface ReleaseContext {
  releaseId: string;
  codeDigest: string;
  contentSnapshotId: string;
  assetUrl(logicalPath: string): string;
}

export interface RenderFragmentRequest {
  fragmentId: string;
  content: unknown;
  release: ReleaseContext;
}

export interface RenderIslandRequest {
  islandId: string;
  component: string;
  props: Record<string, unknown>;
  requestContext: RequestContext;
  release: ReleaseContext;
}

export interface RenderResult {
  html: string;
  status?: number;
  headers?: Record<string, string>;
  cachePolicy?: CachePolicy;
}

export interface RenderPageResult extends RenderResult {
  islands?: IslandDescriptor[];
}

export interface IslandDescriptor {
  islandId: string;
  component: string;
  props: Record<string, unknown>;
  mode: 'ssr' | 'client';
  varyDimensions?: VaryDimension[];
}

export interface CachePolicy {
  scope: 'public' | 'private' | 'no-store';
  ttl?: number;
  staleWhileRevalidate?: number;
  tags?: string[];
}
