/**
 * Push notification provider factory.
 *
 * Creates a PushProvider based on PUSH_PROVIDER env var.
 * Defaults to 'mock' since no push infra is wired yet.
 */

import { ExpoPushProvider } from './providers/expo.js';
import { MockPushProvider } from './providers/mock.js';
import type { PushProvider, PushProviderType } from './types.js';

let _provider: PushProvider | null = null;

export function getPush(): PushProvider {
  if (!_provider) {
    const type = (process.env.PUSH_PROVIDER || 'mock') as PushProviderType;
    _provider = createPushProvider(type);
  }
  return _provider;
}

export function createPushProvider(type: PushProviderType): PushProvider {
  switch (type) {
    case 'expo':
      return new ExpoPushProvider();
    case 'firebase':
      throw new Error('Firebase push provider not yet implemented. Use expo or mock.');
    case 'mock':
      return new MockPushProvider();
    default:
      throw new Error(`Unknown PUSH_PROVIDER: '${type}'. Valid: expo, firebase, mock`);
  }
}

export function setPush(provider: PushProvider): void {
  _provider = provider;
}

export function _resetPush(): void {
  _provider = null;
}
