import { simpleStreamingEnabled } from './config';
import { MockMediaProvider } from './providers/mock';
import type { MediaProvider, MediaSessionCreateInput, MediaSessionCreateResult } from './types';

const providerName = (process.env.MEDIA_PROVIDER ?? 'mock').toLowerCase();

const createProvider = (): MediaProvider => {
  switch (providerName) {
    case 'mock':
      return new MockMediaProvider();
    default:
      throw new Error(`Unsupported MEDIA_PROVIDER: ${providerName}`);
  }
};

export const mediaProvider = createProvider();
export const mediaProviderRuntimeEnabled = !simpleStreamingEnabled;

export const createLiveMediaSession = async (
  input: MediaSessionCreateInput,
): Promise<MediaSessionCreateResult | null> => {
  if (!mediaProviderRuntimeEnabled) {
    return null;
  }

  return mediaProvider.createSession(input);
};
