export class FireMessagingServiceService {
  async requestPermission(): Promise<string | null> {
    if (typeof window === 'undefined' || !('Notification' in window)) {
      return null;
    }
    const permission = await Notification.requestPermission();
    return permission === 'granted' ? 'granted' : null;
  }

  listenForMessages(handler: (payload: unknown) => void): () => void {
    const listener = (event: Event) => handler(event);
    window.addEventListener('message', listener);
    return () => window.removeEventListener('message', listener);
  }
}

export const fireMessagingService = new FireMessagingServiceService();

