export type GenSession = {
  id: string;
  createdAt: number;
  prompt: string;
  refImages: string[];
  count: number;
  images: GenImage[];
  characterSpec?: CharacterSpec;
  packs?: AssetPack[];
  exports?: ExportManifest[];
};

export type GenImage = {
  id: string;
  url: string;
  prompt: string;
  status: 'pending' | 'selected' | 'rejected';
  meta?: Record<string, unknown>;
};

export type GenerateRequest = {
  prompt: string;
  refImages?: string[];
  count: number;
  style?: string;
};

export type GenerateResponse = {
  sessionId: string;
  images: GenImage[];
  provider: 'mock' | 'poe' | 'openrouter';
};

export type PackKind = 'patent' | 'production' | 'marketing';

export type AssetStatus = 'draft' | 'selected' | 'needs_regen' | 'approved' | 'exported';

export type CharacterSpec = {
  name: string;
  oneLiner: string;
  targetUser: string;
  speciesShape: string;
  bodyRatio: string;
  faceFeatures: string;
  colorPalette: string[];
  materials: string[];
  accessories: string[];
  signatureElements: string[];
  manufacturingNotes: string[];
  patentFocus: string[];
  marketingAngle: string[];
  negativePrompt: string;
  sourceImageId?: string;
  sourceImageUrl?: string;
  lockedAt: number;
};

export type AssetTemplate = {
  id: string;
  kind: PackKind;
  view: string;
  title: string;
  description: string;
  required: boolean;
  aspectRatio: '1:1' | '3:4' | '4:5' | '9:16' | '16:9' | 'long';
  filenamePart: string;
  promptTemplate: string;
  checklist: string[];
};

export type ToyAsset = {
  id: string;
  templateId: string;
  kind: PackKind;
  view: string;
  title: string;
  description: string;
  url: string;
  prompt: string;
  status: AssetStatus;
  version: string;
  aspectRatio: AssetTemplate['aspectRatio'];
  required: boolean;
  createdAt: number;
  meta?: Record<string, unknown>;
};

export type AssetPack = {
  id: string;
  kind: PackKind;
  sessionId: string;
  sourceImageId: string;
  sourceImageUrl: string;
  characterSpec: CharacterSpec;
  assets: ToyAsset[];
  manifestId: string;
  createdAt: number;
  version: string;
  status: 'draft' | 'complete';
};

export type ExportManifest = {
  id: string;
  sessionId: string;
  packId: string;
  packKind: PackKind;
  version: string;
  createdAt: number;
  filenameSchema: string;
  source: {
    prompt: string;
    sourceImageId: string;
    sourceImageUrl: string;
  };
  characterSpec: CharacterSpec;
  files: Array<{
    assetId: string;
    templateId: string;
    filename: string;
    url: string;
    kind: PackKind;
    view: string;
    title: string;
    required: boolean;
    aspectRatio: AssetTemplate['aspectRatio'];
    prompt: string;
    checklist: string[];
  }>;
  exportTargets: Array<'zip' | 'pdf' | 'manifest-json'>;
};

export type GeneratePackRequest = {
  sessionId: string;
  imageId: string;
  kind: PackKind;
};

export type GeneratePackResponse = {
  pack: AssetPack;
  manifest: ExportManifest;
  provider: 'mock' | 'poe';
};
