o
    ƒh�j~  ã                   @   s�   d dl Z d dlmZmZ d dlmZ dedededB fdd„ZdedededB fd	d
„ZdedededB fdd„Z	dedededefdd„Z
dS )é    N)ÚdatetimeÚtimezone)ÚAsyncDatabaseÚdbÚ
session_idÚreturnc                 Ã   sH   �| d   |dddgidœ¡ dd¡}|jdd	�I d H }|r"|d
 S d S )NÚconversationsz$ninÚendedÚENDED)Ú	sessionIdÚstatusÚ	createdAtéÿÿÿÿé   ©Úlengthr   ©ÚfindÚsortÚto_list©r   r   ÚcursorÚresults© r   úI/web/html/dev/chatbot/backend/app/repositories/conversation_repository.pyÚ%get_active_conversation_by_session_id   s   €
þýr   c                 Ã   s>   �| d   d|i¡ dd¡}|jdd�I d H }|r|d S d S )Nr   r   r   r   r   r   r   r   r   r   r   r   Úget_conversation_by_session_id   s   €r   Úconversation_idc                 Ã   s   �| d   d|i¡I d H S )Nr   ÚconversationId)Úfind_one)r   r   r   r   r   Úget_conversation_by_id   s   €r    Úsite_idc                 Ã   sŽ   �t | |ƒI d H }|r|S t| |ƒI d H }|r | d¡dvr |S dt ¡ jd d… › �}t tj	¡}|||d||dœ}| d  
|¡I d H  |S )Nr   )r	   r
   Úconv_é   Úopen)r   r   ÚsiteIdr   r   Ú	updatedAtr   )r   r   ÚgetÚuuidÚuuid4Úhexr   Únowr   ÚutcÚ
insert_one)r   r   r!   Úactive_convÚlatest_convÚconv_idr+   Úconv_docr   r   r   Úget_or_create_conversation   s$   €ú	r2   )r(   r   r   Úpymongo.asynchronous.databaser   ÚstrÚdictr   r   r    r2   r   r   r   r   Ú<module>   s    