Ë
    zëjS  ã            
       ó˜  — d dl mZmZmZmZmZm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mZmZmZmZmZmZ d dlmZmZmZmZmZmZmZmZm Z  d dl!m"Z"  ed	g¬
«      Z#de$e   de%de%de%ddf
d„Z&dededededef
d„Z'e#jQ                  ded¬«       ee
«       ee«      fdedefd„«       Z)e#jU                  deejV                  d¬«       ee
«       ee«      fdedededefd„«       Z,e#jU                  d eejV                  d!¬«       ee
«       ee«      fdedededefd"„«       Z-e#jQ                  d#ed$¬«       ed%d&¬'«       ee
«       ee«      fd(e.dedefd)„«       Z/e#jQ                  d*ed+¬«       ee
«       ee«      fdedefd,„«       Z0e#jU                  d-ed.¬«       ee
«       ee«      fdededefd/„«       Z1e#jU                  d0ed1¬«       ee
«       ee«      fdedefd2„«       Z2e#jU                  d3ed4¬«       ee
«       ee«      fdedefd5„«       Z3e#jU                  d6ed7¬«       ee
«       ee«      fdededefd8„«       Z4y)9é    )Ú	APIRouterÚBackgroundTasksÚDependsÚHTTPExceptionÚQueryÚstatus)ÚSession)Úget_db)Úrequire_admin_token)ÚUser)ÚMemberNotificationIdRequestÚMemberNotificationListResponseÚ%MemberNotificationUnreadCountResponseÚMessageÚ!NotificationRecipientListResponseÚSendMemberNotificationRequestÚSendMemberNotificationResponse)	Úclear_all_member_notificationsÚ'count_unread_admin_member_notificationsÚdelete_member_notificationÚlist_member_notificationsÚlist_notification_recipientsÚ"mark_all_member_notifications_readÚmark_member_notification_readÚsend_member_notificationÚserialize_member_notification)Úsend_member_notification_emailzadmin-member-notifications)ÚtagsÚtargetsÚtitleÚmessageÚnotification_typeÚreturnNc             ƒ   ó€   K  — | D ]$  }	 t        |j                  |||¬«      ƒ d {  –—†  Œ& y 7 Œ# t        $ r Y Œ5w xY w­w)N©r    r!   r"   )r   ÚemailÚ	Exception)r   r    r!   r"   Úmembers        úD/var/www/html/kelly/kelly-backend/app/routers/admin/notifications.pyÚ_email_notification_batchr*       sQ   è ø€ ó ˆð	Ü0Ø—‘ØØØ"3ô	÷ ñ ñ ðùô ò 	Ùð	üs(   ‚>‰/¥-¦/ª>­/¯	;¸>º;»>ÚbodyÚbackground_tasksÚdbÚadminc                 óú  — | j                   j                  «       }| j                  j                  «       }|st        t        j
                  d¬«      ‚|st        t        j
                  d¬«      ‚t        ||| j                  | j                  ||¬«      \  }}}| j                  j                  «       j                  «       j                  dd«      }	|j                  t        ||||	¬«       t        d|› �||	||¬	«      S )
NzTitle is required©Ústatus_codeÚdetailzMessage is required)Úuser_idr"   r    r!   Ú Ú_r%   zNotification sent to )r!   Úrecipients_countr"   r    Úrecipient_label)r    Ústripr!   r   r   ÚHTTP_400_BAD_REQUESTr   r3   r"   ÚlowerÚreplaceÚadd_taskr*   r   )
r+   r,   r-   r.   r    r!   Úcountr7   r   Úntypes
             r)   Ú_handle_send_messager?   3   s÷   € ð �J‰J×ÑÓ€EØ�l‰l× Ñ Ó"€GÙÜ¬×(CÑ(CÐL_Ô`Ð`ÙÜ¬×(CÑ(CÐLaÔbÐbä&>Ø
ØØ—‘Ø×0Ñ0ØØô'Ñ#€Eˆ?˜Gð ×"Ñ"×(Ñ(Ó*×0Ñ0Ó2×:Ñ:¸3ÀÓD€EØ×ÑÜ!ØØØØð ô ô *Ø'¨Ð'8Ð9ØØØØ'ôð ó    z/list-notification-recipientsz:List members for the Send Notifications recipient dropdown)Úresponse_modelÚsummaryr5   c                 óD   — t        | «      }t        t        |«      |¬«      S )N)ÚtotalÚmembers)r   r   Úlen)r-   r5   rE   s      r)   Úlist_recipientsrG   Y   s   € ô +¨2Ó.€GÜ,´3°w³<ÈÔQÐQr@   z/send-messagez8Send a message/notification to one member or all members)rA   r1   rB   c                 ó   — t        | |||«      S ©N©r?   ©r+   r,   r-   r.   s       r)   Úsend_messagerL   f   ó   € ô   Ð&6¸¸EÓBÐBr@   z/send-notificationz'Alias for send-message (same behaviour)c                 ó   — t        | |||«      S rI   rJ   rK   s       r)   Úsend_notificationrO   u   rM   r@   z/list-member-notificationsz[List member_notifications rows (inbox: visible only; management page: include_cleared=true)TzHInclude rows hidden from bell (admin_cleared). Set false for inbox-only.)ÚdescriptionÚinclude_clearedc                 ó‚   — t        || ¬«      }|D �cg c]  }t        |«      ‘Œ }}t        t        |«      |¬«      S c c}w )N)rQ   )rD   Únotifications)r   r   r   rF   )rQ   r-   r5   ÚrowsÚnÚ
serializeds         r)   Úlist_member_notifications_routerW   „   sA   € ô % R¸ÔI€DÙ<@ÓA¹D°qÔ/°Õ2¸D€JÐAÜ)´°J³ÈzÔZÐZùò Bs   ’<z"/member-notifications-unread-countzRUnread notification count for admin bell icon (is_read=false, admin_cleared=false)c                 ó,   — t        t        | «      ¬«      S )N)Úunread_count)r   r   )r-   r5   s     r)   Ú'admin_member_notifications_unread_countrZ   –   s   € ô 1Ü<¸RÓ@ôð r@   z/mark-member-notification-readz1Mark one notification as read (sets is_read=true)c                 ó€   — t        || j                  «      }|st        t        j                  d¬«      ‚t        d¬«      S )NúNotification not foundr0   zNotification marked as read©r!   )r   Únotification_idr   r   ÚHTTP_404_NOT_FOUNDr   )r+   r-   r5   Úrows       r)   Ú#mark_member_notification_read_routera   ¤   s9   € ô (¨¨D×,@Ñ,@Ó
A€CÙÜ¬×(AÑ(AÐJbÔcÐcÜÐ8Ô9Ð9r@   z#/mark-all-member-notifications-readz.Mark all visible notifications as read (admin)c                 ó8   — t        | «      }t        d|› d�¬«      S )NzMarked z notification(s) as readr]   )r   r   ©r-   r5   r=   s      r)   Ú(mark_all_member_notifications_read_routerd   ´   s#   € ô /¨rÓ2€EÜ˜W U GÐ+CÐDÔEÐEr@   z/clear-all-member-notificationszLHide all notifications from admin UI (admin_cleared=true; members keep them)c                 ó8   — t        | «      }t        d|› d�¬«      S )NzCleared z  notification(s) from admin viewr]   )r   r   rc   s      r)   Ú$clear_all_member_notifications_routerf   Á   s#   € ô +¨2Ó.€EÜ˜X e WÐ,LÐMÔNÐNr@   z/delete-member-notificationz<Permanently delete one notification from admin notificationsc                 ó|   — t        || j                  «      st        t        j                  d¬«      ‚t        d¬«      S )Nr\   r0   zMember notification deletedr]   )r   r^   r   r   r_   r   )r+   r-   r5   s      r)   Ú delete_member_notification_routerh   Î   s4   € ô & b¨$×*>Ñ*>Ô?Ü¬×(AÑ(AÐJbÔcÐcÜÐ8Ô9Ð9r@   )5Úfastapir   r   r   r   r   r   Úsqlalchemy.ormr	   Úapp.databaser
   Úapp.dependenciesr   Ú
app.modelsr   Úapp.schemasr   r   r   r   r   r   r   Úapp.services.admin_servicer   r   r   r   r   r   r   r   r   Úapp.services.email_otpr   ÚrouterÚlistÚstrr*   r?   ÚgetrG   ÚpostÚHTTP_201_CREATEDrL   rO   ÚboolrW   rZ   ra   rd   rf   rh   © r@   r)   Ú<module>ry      sò  ðß U× UÝ "å Ý 0Ý ÷÷ ñ ÷
÷ 
õ 
õ Bá	Ð5Ð6Ô	7€ðØ�$‰Zðð ðð ð	ð
 ðð 
óð&#Ø
'ð#à%ð#ð 	ð#ð ð	#ð
 $ó#ðL ‡�Ø#Ø4ØHð ó ñ ˜&“/ÙÐ)Ó*ñRØðRàòRóð
Rð ‡�ØØ1Ø×'Ñ'ØFð	 ó ñ ˜&“/ÙÐ-Ó.ñ	CØ
'ðCà%ðCð 	ðCð ò	CóðCð ‡�ØØ1Ø×'Ñ'Ø5ð	 ó ñ ˜&“/ÙÐ-Ó.ñ	CØ
'ðCà%ðCð 	ðCð ò	CóðCð ‡�Ø Ø1Øið ó ñ "ØØ^ôñ ˜&“/ÙÐ)Ó*ñ
[Øð
[ð
 	ð
[ð ò
[óð

[ð ‡�Ø(Ø8Ø`ð ó ñ ˜&“/ÙÐ)Ó*ñØðàòóð
ð ‡�Ø$ØØ?ð ó ñ ˜&“/ÙÐ)Ó*ñ:Ø
%ð:àð:ð ò:óð
:ð ‡�Ø)ØØ<ð ó ñ ˜&“/ÙÐ)Ó*ñFØðFàòFóð
Fð ‡�Ø%ØØZð ó ñ ˜&“/ÙÐ)Ó*ñOØðOàòOóð
Oð ‡�Ø!ØØJð ó ñ ˜&“/ÙÐ)Ó*ñ:Ø
%ð:àð:ð ò:óñ
:r@   