export interface FirebasePublicConfig {
  enabled: boolean;
  projectId: string;
  apiKey: string;
  appId: string;
  messagingSenderId: string;
  vapidKey: string;
}

export function parseFirebasePublicConfig(settings: Record<string, string>): FirebasePublicConfig | null {
  const enabled = ['true', '1', 'yes'].includes((settings.FIREBASE_PUSH_ENABLED ?? '').trim().toLowerCase());
  if (!enabled) return null;

  const projectId = settings.FIREBASE_PROJECT_ID?.trim() ?? '';
  const apiKey = settings.FIREBASE_WEB_API_KEY?.trim() ?? '';
  const appId = settings.FIREBASE_WEB_APP_ID?.trim() ?? '';
  const messagingSenderId = settings.FIREBASE_WEB_MESSAGING_SENDER_ID?.trim() ?? '';
  const vapidKey = settings.FIREBASE_WEB_VAPID_KEY?.trim() ?? '';

  if (!projectId || !apiKey || !appId || !messagingSenderId || !vapidKey) {
    return null;
  }

  return {
    enabled: true,
    projectId,
    apiKey,
    appId,
    messagingSenderId,
    vapidKey
  };
}
