import 'server-only';

import { EmailNotificationProvider } from './email-provider';
import type { NotificationChannel, NotificationProvider } from '../types';

export function getNotificationProvider(
  channel: NotificationChannel,
  organizationId: string,
  providerKey?: string
): NotificationProvider {
  if (channel === 'email') {
    const provider = new EmailNotificationProvider(organizationId);
    if (providerKey && provider.key !== providerKey) {
      throw new Error(`Unsupported email provider: ${providerKey}`);
    }

    return provider;
  }

  throw new Error(`Notification provider for channel ${channel} is not implemented yet.`);
}
