o
    sg                     @   s   d dl m Z  d dlmZ d dlmZmZ d dlmZmZm	Z	m
Z
mZ G dd deeZG dd deZed	krded
ddddddejddd
dZed ed eej ejddd ee dS dS )    )datetime)Enum)ListOptional)	BaseModelEmailStrFieldHttpUrlconstrc                   @   s   e Zd ZdZdZdZdZdS )AccountTypebankersellerbuyervendorN)__name__
__module____qualname__BANKERSELLERBUYERVENDOR r   r   '/var/www/html/XCapMarket/models/user.pyr      s
    r   c                       sV  e Zd ZU edddZeed< eddddZeed< edd	d
Zeed< eddddZ	e
e ed< eddddZe
e ed< edZe
e ed< eddd
Ze
e ed< eejdZeed< eddddZe
e ed< edddZe
e ed< edd dZeed< edd dZeed < ed!dZe
e ed"< eedZee ed#< ed$dZeed%< dZe
e ed&< d'd( Z fd)d*Zd+d, Ze d-efd.d/Z!d0efd1d2Z"d3e
e fd4d5Z#d6efd7d8Z$						dHde
e de
e de
e de
e de
e de
e fd9d:Z%d;d< Z&d=d> Z'd?d@ Z(dAefdBdCZ)dAefdDdEZ*G dFdG dGZ+  Z,S )IUserBase.zUnique identifier for the user)descriptionuser_id   2   )
min_length
max_lengthusernamez0^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$)patternemailNr   
first_name	last_namephonez^https?://[^\s/$.?#].[^\s]*$profile_pic)defaultaccount_type   d   titlei,  )r   	signaturec                   C      t  S Nr   nowr   r   r   r   <lambda>       zUserBase.<lambda>)default_factory
created_atc                   C   r-   r.   r/   r   r   r   r   r1      r2   
updated_at team_idprojectsT	is_active
last_loginc                 C   s   t  | _dS )zUpdate the modified dateN)r   r0   r5   selfr   r   r   update_modify!   s   zUserBase.update_modifyc                    sL   t  jdi |}| jd|d< | jd|d< | jr$| jd|d< |S )Nz%Y-%m-%d %H:%M:%Sr4   r5   r:   r   )super
model_dumpr4   strftimer5   r:   )r<   kwargsdata	__class__r   r   r?   %   s   zUserBase.model_dumpc                 C   s2   ddl m} | }|   ||jd|  S )zSave user to DynamoDBr   )DynamoDBuser)utils.dynamo_dbrE   r=   upload_to_dynamodbdynamodbTabler?   )r<   rE   dbr   r   r   
save_to_db.   s   zUserBase.save_to_dbreturnc                 C   s:   | j r| jr| j  d| j S | j r| j S | jr| jS dS )N r6   )r#   r$   r;   r   r   r   	full_name6   s   zUserBase.full_namenew_usernamec                 C   s2   t |dk st |dkrtd|| _|   dS )zUpdate the usernamer   r   z,Username must be between 3 and 50 charactersN)len
ValueErrorr    r=   )r<   rP   r   r   r   update_username@   s   zUserBase.update_usernamenew_team_idc                 C      || _ |   dS )zUpdate the team IDN)r7   r=   )r<   rT   r   r   r   update_teamG      zUserBase.update_teamnew_account_typec                 C   rU   )zUpdate the account typeN)r(   r=   )r<   rX   r   r   r   update_account_typeL   rW   zUserBase.update_account_typec                 C   s`   |dur|| _ |dur|| _|dur|| _|dur|| _|dur#|| _|dur*|| _|   dS )z&Update multiple profile fields at onceN)r#   r$   r%   r&   r+   r,   r=   )r<   r#   r$   r%   r&   r+   r,   r   r   r   update_profileQ   s   
zUserBase.update_profilec                 C   s   t  | _|   dS )zUpdate the last login timestampN)r   r0   r:   r=   r;   r   r   r   update_last_logini   s   
zUserBase.update_last_loginc                 C      d| _ |   dS )zDeactivate the userFNr9   r=   r;   r   r   r   
deactivaten   rW   zUserBase.deactivatec                 C   r\   )zActivate the userTNr]   r;   r   r   r   activates   rW   zUserBase.activate
project_idc                 C   s.   || j vr| j | |   |   dS dS )z,Add a project ID to the user's projects listN)r8   appendr=   rL   r<   r`   r   r   r   add_projectx   
   
zUserBase.add_projectc                 C   s.   || j v r| j | |   |   dS dS )z1Remove a project ID from the user's projects listN)r8   remover=   rL   rb   r   r   r   remove_project   rd   zUserBase.remove_projectc                   @   s0   e Zd ZdZdddddddd	d
ddddiZdS )zUserBase.ConfigTexampleuser123johndoejohn.doe@example.comJohnDoe+1234567890https://example.com/profile.jpgr   Senior Bankerteam123)r   r    r"   r#   r$   r%   r&   r(   r+   r7   r9   N)r   r   r   from_attributesjson_schema_extrar   r   r   r   Config   s     rs   )NNNNNN)-r   r   r   r   r   str__annotations__r    r"   r#   r   r$   r%   r&   r   r   r(   r+   r,   r4   r   r5   r7   listr8   r   r9   boolr:   r=   r?   rL   propertyrO   rS   rV   rY   rZ   r[   r^   r_   rc   rf   rs   __classcell__r   r   rC   r   r      sd   
 		
r   __main__123ri   rj   rk   rl   rm   rn   signature123ro   )r   r    r"   r#   r$   r%   r&   r(   r,   r+   r7   jane_doe456JanezLead Seller)r#   r+   N)r   enumr   typingr   r   pydanticr   r   r   r	   r
   rt   r   r   r   r   rF   rS   rV   rY   r   rZ   printr   r   r   r   <module>   s6     

