o
    6k~i                     @   s&   d dl mZ d dlmZ dddZdS )    )settings)	messagingNc           	      C   sP  | sdS t tdrtjdu rtd dS z@tj||d}i }|r)dd | D }tj||| tjdd	tj	d
ditj
tjddddd}t|}td|  W dS  tjyf   td|   Y dS  tjyt   td Y dS  tjy } ztd|  W Y d}~dS d}~w ty } ztd|  W Y d}~dS d}~ww )z
    Send FCM notification using Firebase Admin SDK (HTTP v1 API)
    This is the recommended method and works with the new FCM API
    FFIREBASE_APPNz5Firebase not initialized. Check service account file.)titlebodyc                 S   s   i | ]\}}t |t |qS  )str).0kvr   r   ;/var/www/newdalilibackend/backend/notifications/services.py
<dictcomp>   s    z)send_fcm_notification.<locals>.<dictcomp>high)priorityzapns-priority10default)sound)aps)headerspayload)notificationdatatokenandroidapnszSuccessfully sent FCM message: TzFCM token is unregistered: zFCM sender ID mismatchzFCM invalid argument: z Error sending FCM notification: )hasattrr   r   printr   NotificationitemsMessageAndroidConfig
APNSConfigAPNSPayloadApssendUnregisteredErrorSenderIdMismatchErrorInvalidArgumentError	Exception)		fcm_tokenr   messager   r   message_datamessage_objresponseer   r   r   send_fcm_notification   sZ   

r/   )N)django.confr   firebase_adminr   r/   r   r   r   r   <module>   s    