import type { PlatformType } from '@media-manager/shared';
import { BasePlatformAdapter } from './base.js';
import { DouyinAdapter } from './douyin.js';
import { KuaishouAdapter } from './kuaishou.js';
import { BilibiliAdapter } from './bilibili.js';
import { XiaohongshuAdapter } from './xiaohongshu.js';
import { WeixinAdapter } from './weixin.js';

export { BasePlatformAdapter } from './base.js';
export { DouyinAdapter } from './douyin.js';
export { KuaishouAdapter } from './kuaishou.js';
export { BilibiliAdapter } from './bilibili.js';
export { XiaohongshuAdapter } from './xiaohongshu.js';
export { WeixinAdapter } from './weixin.js';

/**
 * 平台适配器注册表
 */
const adapterRegistry: Map<PlatformType, new () => BasePlatformAdapter> = new Map([
  ['douyin', DouyinAdapter],
  ['kuaishou', KuaishouAdapter],
  ['bilibili', BilibiliAdapter],
  ['xiaohongshu', XiaohongshuAdapter],
  ['weixin_video', WeixinAdapter],
]);

/**
 * 获取平台适配器实例
 */
export function getAdapter(platform: PlatformType): BasePlatformAdapter {
  const AdapterClass = adapterRegistry.get(platform);
  if (!AdapterClass) {
    throw new Error(`Unsupported platform: ${platform}`);
  }
  return new AdapterClass();
}

/**
 * 检查平台是否支持
 */
export function isPlatformSupported(platform: PlatformType): boolean {
  return adapterRegistry.has(platform);
}

/**
 * 获取所有已支持的平台
 */
export function getSupportedPlatforms(): PlatformType[] {
  return Array.from(adapterRegistry.keys());
}
