o
    —•Åg-  ã                   @   sF  d dl mZmZmZmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZ d dlZd dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ e d¡Zeƒ ZG dd„ deƒZG dd„ deƒZe d¡eejƒeejƒfdedefdd„ƒZ e d¡eejƒeejƒfdedefdd„ƒZ!e d¡eejƒeejƒfdedefdd„ƒZ"dS )é    )Ú	APIRouterÚDependsÚHTTPExceptionÚstatus)ÚSession)ÚDictÚAnyÚOptional)Ú	BaseModelN)ÚPushNotificationRequest)Údeps)ÚPushNotificationService)ÚExpoPushNotificationService)ÚsettingsÚ	adimsayarc                   @   sB   e Zd ZU eed< eed< dZeed< dZeeee	f  ed< dS )ÚSendPushNotificationRequestÚtitleÚmessageÚgeneralÚnotification_typeNÚdata)
Ú__name__Ú
__module__Ú__qualname__ÚstrÚ__annotations__r   r   r	   r   r   © r   r   ú//app/app/api/v1/endpoints/push_notifications.pyr      s
   
 r   c                   @   s   e Zd ZU eed< dS )ÚSendPushToUserRequestÚuser_idN)r   r   r   Úintr   r   r   r   r   r      s   
 r   z
/test-sendÚreqÚdbc                 C   s<   t j||j| j| j| j| jd}|sttj	dd‚dddœS )u`   
    í…ŒìŠ¤íŠ¸ ìš©ë„ë¡œ í˜„ìž¬ ë¡œê·¸ì¸í•œ ì‚¬ìš©ìžì—ê²Œ í‘¸ì‹œ ì•Œë¦¼ì„ ë³´ëƒ…ë‹ˆë‹¤.
    ©r"   r   r   r   r   r   ú Failed to send push notification©Ústatus_codeÚdetailÚsuccessz#Push notification sent successfully©r   r   )
r   Úsend_push_to_userÚidr   r   r   r   r   r   ÚHTTP_500_INTERNAL_SERVER_ERROR©r!   r"   Úcurrent_userr(   r   r   r   Útest_send_push_notification   s   ú	þ
r/   z/admin/send-to-userc                 C   sX   |j s
ttjdd‚tj|| j| j| j| j	| j
d}|s#ttjdd‚dd| j› dœS )uL   
    ê´€ë¦¬ìžê°€ íŠ¹ì • ì‚¬ìš©ìžì—ê²Œ í‘¸ì‹œ ì•Œë¦¼ì„ ë³´ëƒ…ë‹ˆë‹¤.
    z9Only admin users can send notifications to specific usersr%   r#   r$   r(   z"Push notification sent to user ID r)   )Úis_adminr   r   ÚHTTP_403_FORBIDDENr   r*   r   r   r   r   r   r,   r-   r   r   r   Úadmin_send_push_to_user;   s&   
þú	þr2   z/expo-test-sendc              
   C   sz   z t j||j| j| j| j| jpdd}|rdddœW S tddd‚ ty< } zt	 
d	t|ƒ› ¡ tddd‚d
}~ww )uh   
    í˜„ìž¬ ë¡œê·¸ì¸í•œ ì‚¬ìš©ìžì—ê²Œ Expo í‘¸ì‹œ ì•Œë¦¼ì„ ë³´ë‚´ëŠ” í…ŒìŠ¤íŠ¸ ì—”ë“œí¬ì¸íŠ¸.
    Útestr#   r(   z(Expo push notification sent successfullyr)   iô  z%Failed to send Expo push notificationr%   z&Error sending Expo push notification: N)r   r*   r+   r   r   r   r   r   Ú	ExceptionÚloggerÚerrorr   )r!   r"   r.   r(   Úer   r   r   Útest_send_expo_push\   s"   	ú	€þr8   )#Úfastapir   r   r   r   Úsqlalchemy.ormr   Útypingr   r   r	   Úpydanticr
   ÚloggingÚapp.schemas.notificationr   Zapp.apir   Ú&app.services.push_notification_servicer   Z+app.services.expo_push_notification_servicer   Úapp.core.configr   Ú	getLoggerr5   Úrouterr   r   ÚpostÚget_dbÚget_current_userr/   r2   r8   r   r   r   r   Ú<module>   sL    
ýÿþ ýÿþ ýÿþ