U
    -h$                     @   s   d dl mZmZ d dlmZ d dlmZmZmZm	Z	 d dl
m
Z
 d dlmZ d dlmZ G dd deeZG d	d
 d
eeZG dd deeZG dd deZdS )    )DocumentIndexed)Field)OptionalDictAnyList)datetime)Enum)ObjectIdc                   @   s   e Zd ZdZdZdZdS )	ThemeModelightZdarkautoN)__name__
__module____qualname__ZLIGHTZDARKAUTO r   r   M/var/www/html/Mana-Pige/backend/account-service/app/models/user_preference.pyr      s   r   c                   @   s(   e Zd ZdZdZdZdZdZdZdZ	dS )	LanguageenesfrdeptzhjaN)
r   r   r   ENGLISHZSPANISHZFRENCHZGERMANZ
PORTUGUESEZCHINESEZJAPANESEr   r   r   r   r      s   r   c                   @   s   e Zd ZdZdZdZdZdS )NotificationFrequencyZ	immediateZdailyZweeklyneverN)r   r   r   	IMMEDIATEDAILYZWEEKLYNEVERr   r   r   r   r      s   r   c                   @   s  e Zd ZU eedded< ejZeed< e	j
Ze	ed< dZeed< dZeed	< d
Zeed< dZeed< dZeed< dZeed< edd dZeeef ed< ejZeed< ejZeed< edd dZeeef ed< edd dZeeef ed< edd dZeeef ed< edd dZ eeef ed< ee!dZ"eeef ed< ee!dZ#eeef ed< ee$j%dZ&e$ed < ee$j%dZ'e$ed!< G d"d# d#Z(G d$d% d%Z)e*ed d&d'd(Z+eed)d*d+Z,eed,d-d.Z-eed,d/d0Z.eed1d2d3Z/eeef d4d5d6Z0eed7d8d9Z1eed:d;d<Z2eed:d=d>Z3eed7d?d@Z4eeef dAdBdCZ5e*eeeef d dDdEdFZ6dGS )HUserPreferenceT)uniqueuser_idthemelanguageUTCtimezonez
YYYY-MM-DDdate_formatZ24time_formatemail_notificationspush_notificationsFsms_notificationsc                   C   s   ddddddddddd
S )NTF)
Zsecurity_alertsZaccount_updatesZmarketing_emailsZproduct_updatesZfriend_requestsZmessagesZmentionscommentsZlikesZ	followersr   r   r   r   r   <lambda>-   s    zUserPreference.<lambda>)default_factorynotification_preferencesemail_frequencydigest_frequencyc                   C   s   ddddddddddd
S )NpublicTF)
Zprofile_visibilityZsearch_visibilityZshow_online_statusZshow_last_seenZallow_friend_requestsZallow_messages_from_strangersZ
show_emailZ
show_phoneZdata_collection_consentZanalytics_trackingr   r   r   r   r   r0   ?   s    privacy_settingsc                   C   s   dddddddS )NFT   )Ztwo_factor_enabledZlogin_notificationsZunusual_activity_alertsZpassword_expiry_remindersession_timeoutZ&require_password_for_sensitive_actionsr   r   r   r   r   r0   M   s    security_settingsc                   C   s   ddddddddS )Nr   FTZmedium   )Zcontent_languageZmature_contentZauto_play_videosZhigh_contrast_modeZreduce_motionZ	font_sizeZposts_per_pager   r   r   r   r   r0   W   s    content_preferencesc                   C   s   ddddddS )NemailF)Zpreferred_contact_methodZmarketing_consentZnewsletter_subscriptionZsurvey_participationZbeta_programr   r   r   r   r   r0   b   s    communication_settingsapp_settingscustom_preferences
created_at
updated_atc                   @   s   e Zd ZdZdS )zUserPreference.ConfigTN)r   r   r   arbitrary_types_allowedr   r   r   r   Configt   s   rC   c                   @   s   e Zd ZdZddddgZdS )zUserPreference.SettingsZuser_preferencesr%   r'   r&   rA   N)r   r   r   nameindexesr   r   r   r   Settingsw   s   rF   )r%   returnc                    s   | |d}|  I dH  |S )z)Create default preferences for a new user)r%   N)save)clsr%   Zpreferencesr   r   r   create_default_preferences   s    
z)UserPreference.create_default_preferences)notification_typeenabledc                    s&   || j |< t | _|  I dH  dS )z)Update a specific notification preferenceN)r2   r	   utcnowrA   rH   )selfrK   rL   r   r   r   update_notification_preference   s    

z-UserPreference.update_notification_preference)setting_namevaluec                    s&   || j |< t | _|  I dH  dS )zUpdate a privacy settingN)r6   r	   rM   rA   rH   rN   rP   rQ   r   r   r   update_privacy_setting   s    

z%UserPreference.update_privacy_settingc                    s&   || j |< t | _|  I dH  dS )zUpdate a security settingN)r9   r	   rM   rA   rH   rR   r   r   r   update_security_setting   s    

z&UserPreference.update_security_setting)preference_namerQ   c                    s&   || j |< t | _|  I dH  dS )zUpdate a content preferenceN)r;   r	   rM   rA   rH   )rN   rU   rQ   r   r   r   update_content_preference   s    

z(UserPreference.update_content_preference)updatesc                    s   |  D ]\}}|dkr&| j| q|dkr<| j| q|dkrR| j| q|dkrh| j| q|dkr~| j| q|dkr| j| q|dkr| j| qt	| |rt
| || qt | _|  I dH  dS )	z Bulk update multiple preferencesr2   r6   r9   r;   r=   r>   r?   N)itemsr2   updater6   r9   r;   r=   r>   r?   hasattrsetattrr	   rM   rA   rH   )rN   rW   categorysettingsr   r   r   bulk_update_preferences   s&    

z&UserPreference.bulk_update_preferences)rK   rG   c                 C   s   | j |dS )z&Get a specific notification preferenceF)r2   getrN   rK   r   r   r   get_notification_preference   s    z*UserPreference.get_notification_preference)rP   rG   c                 C   s   | j |S )zGet a privacy setting)r6   r_   rN   rP   r   r   r   get_privacy_setting   s    z"UserPreference.get_privacy_settingc                 C   s   | j |S )zGet a security setting)r9   r_   rb   r   r   r   get_security_setting   s    z#UserPreference.get_security_settingc                 C   sH   |dkr>|dkr| j sdS |dkr,| js,dS |dkr>| js>dS | |S )z0Check if a specific notification type is enabled)r<   pushsmsr<   Fre   rf   )r,   r-   r.   ra   r`   r   r   r   is_notification_enabled   s    z&UserPreference.is_notification_enabled)rG   c                    sZ   t | j| j| j| j| j| j| j| j| j	| j
| j| j| j| j| j| j| j| j| j| jdS )z&Export all preferences as a dictionary)r%   r&   r'   r)   r*   r+   r,   r-   r.   r2   r3   r4   r6   r9   r;   r=   r>   r?   r@   rA   )strr%   r&   r'   r)   r*   r+   r,   r-   r.   r2   r3   r4   r6   r9   r;   r=   r>   r?   r@   rA   )rN   r   r   r   export_preferences   s*    z!UserPreference.export_preferences)r%   preferences_datarG   c                    sb   | dd | dd | dd | | j|kI dH }|sN| |I dH }||I dH  |S )z$Import preferences from a dictionaryr%   Nr@   rA   )popfind_oner%   rJ   r^   )rI   r%   rj   Z
user_prefsr   r   r   import_preferences   s    z!UserPreference.import_preferencesN)7r   r   r   r   r   __annotations__r   r   r&   r   r   r'   r)   rh   r*   r+   r,   boolr-   r.   r   r2   r   r   r    r3   r!   r4   r6   r   r9   r;   r=   dictr>   r?   r	   rM   r@   rA   rC   rF   classmethodrJ   rO   rS   rT   rV   r^   ra   rc   rd   rg   ri   rm   r   r   r   r   r#      sH   

		r#   N)beanier   r   pydanticr   typingr   r   r   r   r	   enumr
   bsonr   rh   r   r   r   r#   r   r   r   r   <module>   s   	