U
    g'                     @   s   d Z ddlZddlmZmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ erddlmZ G dd deZG dd deZG dd deZG dd deZG dd deZdS )zFThis module contains the classes that represent Telegram MessageOigin.    N)TYPE_CHECKINGDictFinalOptionalType)	constants)Chat)TelegramObject)User)enum)extract_tzinfo_from_defaultsfrom_timestamp)JSONDict)Botc                       s   e Zd ZU dZdZejjZee	 e
d< ejjZee	 e
d< ejjZee	 e
d< ejjZee	 e
d< dde	ejee d	 fd
dZedee ed ed  d fddZ  ZS )MessageOrigina  
    Base class for telegram MessageOrigin object, it can be one of:

    * :class:`MessageOriginUser`
    * :class:`MessageOriginHiddenUser`
    * :class:`MessageOriginChat`
    * :class:`MessageOriginChannel`

    Objects of this class are comparable in terms of equality. Two objects of this class are
    considered equal, if their :attr:`type` and :attr:`date` are equal.

    .. versionadded:: 20.8

    Args:
        type (:obj:`str`): Type of the message origin, can be on of:
            :attr:`~telegram.MessageOrigin.USER`, :attr:`~telegram.MessageOrigin.HIDDEN_USER`,
            :attr:`~telegram.MessageOrigin.CHAT`, or :attr:`~telegram.MessageOrigin.CHANNEL`.
        date (:obj:`datetime.datetime`): Date the message was sent originally.
            |datetime_localization|

    Attributes:
        type (:obj:`str`): Type of the message origin, can be on of:
            :attr:`~telegram.MessageOrigin.USER`, :attr:`~telegram.MessageOrigin.HIDDEN_USER`,
            :attr:`~telegram.MessageOrigin.CHAT`, or :attr:`~telegram.MessageOrigin.CHANNEL`.
        date (:obj:`datetime.datetime`): Date the message was sent originally.
            |datetime_localization|
    )datetypeUSERHIDDEN_USERCHATCHANNELN
api_kwargsr   r   r   c                   s@   t  j|d ttj||| _|| _| j| jf| _| 	  d S )Nr   )
super__init__r   Z
get_memberr   MessageOriginTyper   r   Z	_id_attrsZ_freeze)selfr   r   r   	__class__ ;/tmp/pip-unpacked-wheel-swnnwir2/telegram/_messageorigin.pyr   N   s    zMessageOrigin.__init__r   )databotreturnc                    s   |  |}|sdS | jt| jt| jt| jti}| t	kr\|
d|kr\||d j||dS t|}t|
d|d|d< d|krt|
d||d< d|krt|
d||d< d|krt|
d||d< t j||dS )	zConverts JSON data to the appropriate :class:`MessageOrigin` object, i.e. takes
        care of selecting the correct subclass.
        Nr   )r"   r#   r   )tzinfosender_usersender_chatchat)Z_parse_datar   MessageOriginUserr   MessageOriginHiddenUserr   MessageOriginChatr   MessageOriginChannelr   getpopde_jsonr   r   r
   r   r   )clsr"   r#   Z_class_mappingZ
loc_tzinfor   r    r!   r/   `   s.    
    zMessageOrigin.de_json)N)__name__
__module____qualname____doc__	__slots__r   r   r   r   str__annotations__r   r   r   datetimer   r   r   classmethodr/   __classcell__r    r    r   r!   r   #   s&   
  r   c                       s:   e Zd ZdZdZddejeee d fddZ	  Z
S )r)   av  
    The message was originally sent by a known user.

    .. versionadded:: 20.8

    Args:
        date (:obj:`datetime.datetime`): Date the message was sent originally.
            |datetime_localization|
        sender_user (:class:`telegram.User`): User that sent the message originally.

    Attributes:
        type (:obj:`str`): Type of the message origin. Always
            :tg-const:`~telegram.MessageOrigin.USER`.
        date (:obj:`datetime.datetime`): Date the message was sent originally.
            |datetime_localization|
        sender_user (:class:`telegram.User`): User that sent the message originally.
    )r&   Nr   )r   r&   r   c             	      s2   t  j| j||d |   || _W 5 Q R X d S Nr   )r   r   r   	_unfrozenr&   )r   r   r&   r   r   r    r!   r      s    
zMessageOriginUser.__init__)r1   r2   r3   r4   r5   r8   r
   r   r   r   r:   r    r    r   r!   r)      s   r)   c                       s:   e Zd ZdZdZddejeee d fddZ	  Z
S )r*   a  
    The message was originally sent by an unknown user.

    .. versionadded:: 20.8

    Args:
        date (:obj:`datetime.datetime`): Date the message was sent originally.
            |datetime_localization|
        sender_user_name (:obj:`str`): Name of the user that sent the message originally.

    Attributes:
        type (:obj:`str`): Type of the message origin. Always
            :tg-const:`~telegram.MessageOrigin.HIDDEN_USER`.
        date (:obj:`datetime.datetime`): Date the message was sent originally.
            |datetime_localization|
        sender_user_name (:obj:`str`): Name of the user that sent the message originally.
    )sender_user_nameNr   )r   r=   r   c             	      s2   t  j| j||d |   || _W 5 Q R X d S r;   )r   r   r   r<   r=   )r   r   r=   r   r   r    r!   r      s    
z MessageOriginHiddenUser.__init__)r1   r2   r3   r4   r5   r8   r6   r   r   r   r:   r    r    r   r!   r*      s   r*   c                       sB   e Zd ZdZdZdddejeee ee	 d fddZ
  ZS )	r+   a  
    The message was originally sent on behalf of a chat to a group chat.

    .. versionadded:: 20.8

    Args:
        date (:obj:`datetime.datetime`): Date the message was sent originally.
            |datetime_localization|
        sender_chat (:class:`telegram.Chat`): Chat that sent the message originally.
        author_signature (:obj:`str`, optional): For messages originally sent by an anonymous chat
            administrator, original message author signature

    Attributes:
        type (:obj:`str`): Type of the message origin. Always
            :tg-const:`~telegram.MessageOrigin.CHAT`.
        date (:obj:`datetime.datetime`): Date the message was sent originally.
            |datetime_localization|
        sender_chat (:class:`telegram.Chat`): Chat that sent the message originally.
        author_signature (:obj:`str`): Optional. For messages originally sent by an anonymous chat
            administrator, original message author signature
    )author_signaturer'   Nr   )r   r'   r>   r   c             	      s8   t  j| j||d |   || _|| _W 5 Q R X d S r;   )r   r   r   r<   r'   r>   )r   r   r'   r>   r   r   r    r!   r      s    
zMessageOriginChat.__init__)N)r1   r2   r3   r4   r5   r8   r   r   r6   r   r   r:   r    r    r   r!   r+      s   	 r+   c                       sD   e Zd ZdZdZdddejeeee	 ee
 d fddZ  ZS )	r,   a  
    The message was originally sent to a channel chat.

    .. versionadded:: 20.8

    Args:
        date (:obj:`datetime.datetime`): Date the message was sent originally.
            |datetime_localization|
        chat (:class:`telegram.Chat`): Channel chat to which the message was originally sent.
        message_id (:obj:`int`): Unique message identifier inside the chat.
        author_signature (:obj:`str`, optional): Signature of the original post author.

    Attributes:
        type (:obj:`str`): Type of the message origin. Always
            :tg-const:`~telegram.MessageOrigin.CHANNEL`.
        date (:obj:`datetime.datetime`): Date the message was sent originally.
            |datetime_localization|
        chat (:class:`telegram.Chat`): Channel chat to which the message was originally sent.
        message_id (:obj:`int`): Unique message identifier inside the chat.
        author_signature (:obj:`str`): Optional. Signature of the original post author.
    )r>   r(   
message_idNr   )r   r(   r?   r>   r   c             	      s>   t  j| j||d |   || _|| _|| _W 5 Q R X d S r;   )r   r   r   r<   r(   r?   r>   )r   r   r(   r?   r>   r   r   r    r!   r     s
    	
zMessageOriginChannel.__init__)N)r1   r2   r3   r4   r5   r8   r   intr   r6   r   r   r:   r    r    r   r!   r,      s    r,   )r4   r8   typingr   r   r   r   r   Ztelegramr   Ztelegram._chatr   Ztelegram._telegramobjectr	   Ztelegram._userr
   Ztelegram._utilsr   Ztelegram._utils.datetimer   r   Ztelegram._utils.typesr   r   r   r)   r*   r+   r,   r    r    r    r!   <module>   s    a""+