import * as OpenAiImpl from './platforms/openai';

const SUPPORTED_PLATFORMS = { OpenAi: OpenAiImpl } as const;

export * as OpenAi from './platforms/openai';
export type PlatformConfig = OpenAiImpl.PlatformConfig;
export type PlatformEventEmitter = OpenAiImpl.PlatformEventEmitter;

export const createAiClient = (configParams: PlatformConfig): PlatformEventEmitter => {
  const {
    platform,
    platformConfiguration,
  } = configParams;

  const platformModules = Object.values(SUPPORTED_PLATFORMS);
  const platformModule = platformModules.find((p) => p.PLATFORM_ID === platform);

  if (!platformModule) {
    const supportedPlatforms = platformModules.map((p) => p.PLATFORM_ID).join(', ');
    throw new Error(`Unsupported platform: ${platform}. Supported platforms are: ${supportedPlatforms}`);
  }

  return new platformModule.PlatformEventEmitterImpl(platformConfiguration);
};
