o
    zgF                     @   s  d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZmZ d dlmZ d dlmZ e Zejd	ed
eejeejfdedefddZejd	ee d
eejeejfdedefddZejdee d
eejeejfdefddZejdee d
eejeejfdefddZejdee d
eejeejfdedefddZejdee d
eejeejfdedefddZdS )     )List)	APIRouterDependsHTTPException)Session)funccase)deps)MessageCreateMessageResponse)Message)message_service/)response_modelpayloaddbc                 C   s   t ||j| j| j}|S )z
    Allows the currently logged-in user to send a new message.
    The sender_id is derived from the authenticated user's ID,
    and the message is saved based on the receiver_id and content from the payload.
    )r   Zcreate_messageidreceiver_idcontent)r   r   current_usermessage r   %/app/app/api/v1/endpoints/messages.pysend_message   s   r   	friend_idc                 C   $   t ||j| }|stddd|S )zS
    Retrieves the conversation history between the current user and a friend.
      No conversation foundstatus_codedetailr   Zget_messages_between_usersr   r   r   r   r   messagesr   r   r   get_messages      	r$   z/unreadc                 C   s   t j| |jd}|S )zG
    Retrieves all unread messages for the current logged-in user.
    )r   )r   get_unread_messagesr   )r   r   Zunreadr   r   r   r&   )   s   r&   z/threadsc                 C   s"   t | |j}|stddd|S )u   
    로그인한 사용자가 참여하는 모든 대화 스레드를 조회합니다.
    각 스레드는 해당 대화 상대(친구)와의 최신 메시지를 포함합니다.
    r   zNo conversations found.r   )r   get_conversation_threadsr   r   )r   r   threadsr   r   r   r'   4   s   	r'   z/conversation/{friend_id}c                 C   r   )zd
    Retrieves the full conversation history between the current user and the specified friend.
    r   r   r   r!   r"   r   r   r   get_conversation_with_userB   r%   r)   z/read	sender_idc                 C   s   t j||j| d}|S )u   
    POST /api/v1/messages/read

    현재 로그인한 사용자의, 특정 발신자(sender_id)로부터 온 메시지를 읽음 처리합니다.
    )r   r*   )r   Zmark_messages_as_readr   )r*   r   r   Zupdated_messagesr   r   r   mark_messages_as_read_endpointP   s   r+   N) typingr   fastapir   r   r   sqlalchemy.ormr   
sqlalchemyr   r   Zapp.apir	   Zapp.schemas.messager
   r   Zapp.models.messager   Zapp.servicesr   routerpostget_dbget_current_userr   getintr$   r&   r'   r)   r+   r   r   r   r   <module>   sj   
