
    i                         d dl mZ d dlmZ d dlmZ  G d dej
                        Z G d dej
                        Z G d d	ej
                        Zy
)    )
SQLAlchemy)datetime)dbc                      e Zd Z ej                  ej
                  d      Z ej                   ej                  d      d      Z ej                  ej                  d      Z
 ej                  ej                  ej                        Z ej                  dddd	      Z ej                  d
ddd	      Zd Zd Zy)ChatRoomTprimary_keyd   nullabledefaultChatMessageroomzall, delete-orphan)backreflazycascadeChatParticipantc                 "    d| j                    dS )Nz
<ChatRoom >idselfs    D/home/kdj-ubuntu1/mlink_AI_Server/mlink-backend/./src/models/chat.py__repr__zChatRoom.__repr__   s    DGG9A&&    c                    | j                   | j                  | j                  | j                  r| j                  j	                         nd t        | j                        | j                  r| j                  d   j                         dS d dS )N)r   name
is_private
created_atparticipant_countlast_message)	r   r    r!   r"   	isoformatlenparticipantsmessagesto_dictr   s    r   r)   zChatRoom.to_dict   ss    ''II//9=$//335d!$T%6%6!7;?==DMM"-557
 	
 OS
 	
r   N)__name__
__module____qualname__r   ColumnIntegerr   Stringr    Booleanr!   DateTimer   utcnowr"   relationshipr(   r'   r   r)    r   r   r   r      s    	2::4	0B299YRYYs^d3D2::t4J2;;@J r}f4QefH"2??#4f4YmnL'
r   r   c                      e Zd Z ej                  ej
                  d      Z ej                  ej
                   ej                  d      d      Z ej                  ej
                   ej                  d      d      Z	 ej                  ej                  ej                        Z ej                  ej                  ej                        Z ej                  d ej                   d	d
            Zd Zd Zy)r   Tr   chat_room.idFr   user.idr   Userchat_participationsr   r   c                 <    d| j                    d| j                   dS )Nz<ChatParticipant z in r   )user_idroom_idr   s    r   r   zChatParticipant.__repr__&   s    "4<<.T\\N!DDr   c                 0   | j                   | j                  | j                  | j                  r| j                  j                  nd | j
                  r| j
                  j                         nd | j                  r| j                  j                         dS d dS )N)r   r>   r=   username	joined_atlast_read_at)r   r>   r=   userr@   rA   r%   rB   r   s    r   r)   zChatParticipant.to_dict)   sy    ''||||.2ii		**T7;~~1134=A=N=ND--779
 	
 UY
 	
r   N)r*   r+   r,   r   r-   r.   r   
ForeignKeyr>   r=   r1   r   r2   rA   rB   r3   r   rC   r   r)   r4   r   r   r   r      s    	2::4	0Bbii

MBMM.$AERGbii

MBMM)$<uMG		"++x?I299R[[(//BL 2??6:2::6KRV+WXDE
r   r   c                   x   e Zd Z ej                  ej
                  d      Z ej                  ej
                   ej                  d      d      Z ej                  ej
                   ej                  d      d      Z	 ej                  ej                  d      Z ej                   ej                  d      d	      Z ej                   ej                  d
      d      Z ej                  ej                  ej"                  	      Z ej&                  d ej(                  dd            Zd Zd Zy)r   Tr   r6   Fr   r7      textr   i  r8   sent_messagesr:   r;   c                 "    d| j                    dS )Nz<ChatMessage r   r   r   s    r   r   zChatMessage.__repr__?   s    twwiq))r   c           	      $   | j                   | j                  | j                  | j                  r| j                  j                  nd | j
                  | j                  | j                  | j                  r| j                  j                         dS d dS )N)r   r>   	sender_idsender_usernamecontentmessage_typefile_urlr"   )
r   r>   rK   senderr@   rM   rN   rO   r"   r%   r   s    r   r)   zChatMessage.to_dictB   st    ''||7;{{t{{33|| --9=$//335	
 		
 OS	
 		
r   N)r*   r+   r,   r   r-   r.   r   rD   r>   rK   TextrM   r/   rN   rO   r1   r   r2   r"   r3   r   rP   r   r)   r4   r   r   r   r   3   s    	2::4	0Bbii

MBMM.$AERG		"**mbmmI&>OIbii%0G299YRYYr]F;Lryy3$7H2;;@J R__VZRZZd-STF*

r   r   N)	flask_sqlalchemyr   r   src.models.userr   Modelr   r   r   r4   r   r   <module>rU      s>    '  
rxx 
.
bhh 
.
"(( 
r   