export { SeedancePromptAdapter } from "./seedance.adapter";
export { GeminiOmniPromptAdapter } from "./gemini-omni.adapter";
export { KlingMotionPromptAdapter } from "./kling-motion.adapter";
export { HiggsfieldPromptAdapter } from "./higgsfield.adapter";
export { TikTokUGCPromptAdapter } from "./tiktok-ugc.adapter";
export { BasePromptAdapter } from "./base.adapter";
export type { AdapterValidationResult } from "./base.adapter";

import { SeedancePromptAdapter } from "./seedance.adapter";
import { GeminiOmniPromptAdapter } from "./gemini-omni.adapter";
import { KlingMotionPromptAdapter } from "./kling-motion.adapter";
import { HiggsfieldPromptAdapter } from "./higgsfield.adapter";
import { TikTokUGCPromptAdapter } from "./tiktok-ugc.adapter";
import type { BasePromptAdapter } from "./base.adapter";
import type { PromptVariation } from "@/lib/schemas/universal-prompt.schema";
import type { Platform } from "@/types";

/**
 * Base adapter interface with a loose input type (unknown) so route code
 * can call these methods without hitting the `never` intersection problem
 * caused by TypeScript trying to intersect all platform-specific TInput types.
 */
// Fix #2: constructUserPrompt tidak lagi terima variationIndex.
export interface AnyAdapter {
  platform: Platform;
  validateInput(input: unknown): ReturnType<BasePromptAdapter<unknown>["validateInput"]>;
  constructSystemPrompt(input: unknown, variationCount: number): string;
  constructUserPrompt(input: unknown): string;
  transformOutput(rawOutput: string, input: unknown): PromptVariation;
}

export function getAdapter(platform: Platform): AnyAdapter {
  switch (platform) {
    case "seedance":
      return new SeedancePromptAdapter() as unknown as AnyAdapter;
    case "gemini_omni":
      return new GeminiOmniPromptAdapter() as unknown as AnyAdapter;
    case "kling_motion":
      return new KlingMotionPromptAdapter() as unknown as AnyAdapter;
    case "higgsfield":
      return new HiggsfieldPromptAdapter() as unknown as AnyAdapter;
    case "tiktok_ugc":
      return new TikTokUGCPromptAdapter() as unknown as AnyAdapter;
    default:
      throw new Error(`Unknown platform: ${platform}`);
  }
}
