U
    h#                     @   s   d dl mZmZ d dlmZ ddlmZmZmZ d dl	Z	G dd dZ
G dd	 d	ZG d
d deZejejejejejejejejejejejejiZG dd dZdS )    )OptionalTuple)IntEnum   )InputPeerUserInputPeerChatInputPeerChannelNc                	   @   s<   e Zd ZdZdZeeeeeeeee dddZdd Z	dS )SessionStatea8  
    Stores the information needed to fetch updates and about the current user.

    * user_id: 64-bit number representing the user identifier.
    * dc_id: 32-bit number relating to the datacenter identifier where the user is.
    * bot: is the logged-in user a bot?
    * pts: 64-bit number holding the state needed to fetch updates.
    * qts: alternative 64-bit number holding the state needed to fetch updates.
    * date: 64-bit number holding the date needed to fetch updates.
    * seq: 64-bit-number holding the sequence number needed to fetch updates.
    * takeout_id: 64-bit-number holding the identifier of the current takeout session.

    Note that some of the numbers will only use 32 out of the 64 available bits.
    However, for future-proofing reasons, we recommend you pretend they are 64-bit long.
    user_iddc_idbotptsqtsdateseq
takeout_idc	           	      C   s4   || _ || _|| _|| _|| _|| _|| _|| _d S Nr
   )	selfr   r   r   r   r   r   r   r    r   =/tmp/pip-unpacked-wheel-c81u5j2r/telethon/_updates/session.py__init__   s    zSessionState.__init__c                    s   t  fdd jD S )Nc                    s   i | ]}|t  |qS r   getattr.0kr   r   r   
<dictcomp>-   s      z)SessionState.__repr__.<locals>.<dictcomp>repr	__slots__r   r   r   r   __repr__,   s    zSessionState.__repr__N)
__name__
__module____qualname____doc__r!   intboolr   r   r"   r   r   r   r   r	      s   r	   c                   @   s,   e Zd ZdZdZeedddZdd ZdS )ChannelStatez
    Stores the information needed to fetch updates from a channel.

    * channel_id: 64-bit number representing the channel identifier.
    * pts: 64-bit number holding the state needed to fetch updates.
    
channel_idr   c                 C   s   || _ || _d S r   r*   )r   r+   r   r   r   r   r   9   s    zChannelState.__init__c                    s   t  fdd jD S )Nc                    s   i | ]}|t  |qS r   r   r   r   r   r   r   B   s      z)ChannelState.__repr__.<locals>.<dictcomp>r   r   r   r   r   r"   A   s    zChannelState.__repr__N)r#   r$   r%   r&   r!   r'   r   r"   r   r   r   r   r)   0   s   r)   c                   @   sH   e Zd ZdZedZedZedZedZedZ	edZ
dd	 Zd
S )
EntityTypea  
    You can rely on the type value to be equal to the ASCII character one of:

    * 'U' (85): this entity belongs to a :tl:`User` who is not a ``bot``.
    * 'B' (66): this entity belongs to a :tl:`User` who is a ``bot``.
    * 'G' (71): this entity belongs to a small group :tl:`Chat`.
    * 'C' (67): this entity belongs to a standard broadcast :tl:`Channel`.
    * 'M' (77): this entity belongs to a megagroup :tl:`Channel`.
    * 'E' (69): this entity belongs to an "enormous" "gigagroup" :tl:`Channel`.
    UBGCMEc                 C   s   t |  S )z<
        Return the canonical version of this type.
        )_canon_entity_typesr   r   r   r   	canonicalW   s    zEntityType.canonicalN)r#   r$   r%   r&   ordUSERBOTGROUPCHANNEL	MEGAGROUP	GIGAGROUPr4   r   r   r   r   r,   E   s   
r,   c                   @   s   e Zd ZdZdZeeedddZedd Z	edd Z
ed	d
 ZeedddZedd Zdd Zdd Zdd Zdd ZdS )EntityaD  
    Stores the information needed to use a certain user, chat or channel with the API.

    * ty: 8-bit number indicating the type of the entity (of type `EntityType`).
    * id: 64-bit number uniquely identifying the entity among those of the same type.
    * hash: 64-bit signed number needed to use this entity with the API.

    The string representation of this class is considered to be stable, for as long as
    Telegram doesn't need to add more fields to the entities. It can also be converted
    to bytes with ``bytes(entity)``, for a more compact representation.
    tyidhashc                 C   s   || _ || _|| _d S r   r=   )r   r>   r?   r@   r   r   r   r   v   s    zEntity.__init__c                 C   s   | j tjtjfkS )zC
        ``True`` if the entity is either a user or a bot.
        )r>   r,   r6   r7   r   r   r   r   is_user   s    zEntity.is_userc                 C   s   | j tjtjfkS )z
        ``True`` if the entity is a small group chat or `megagroup`_.

        .. _megagroup: https://telegram.org/blog/supergroups5k
        )r>   r,   r8   r:   r   r   r   r   is_group   s    zEntity.is_groupc                 C   s   | j tjtjfkS )z
        ``True`` if the entity is a broadcast channel or `broadcast group`_.

        .. _broadcast group: https://telegram.org/blog/autodelete-inv2#groups-with-unlimited-members
        )r>   r,   r9   r;   r   r   r   r   is_broadcast   s    zEntity.is_broadcast)stringc              	   C   s   z0| d\}}}t|t|t|  }}}W nJ tk
rT   td|dY n( ttfk
rz   td|dY nX | t|||S )z6
        Convert the string into an `Entity`.
        .zexpected str, got Nz.malformed entity str (must be T.id.hash), got )splitr5   r'   AttributeError	TypeError
ValueErrorr,   )clsrD   r>   r?   r@   r   r   r   from_str   s     zEntity.from_strc                 C   sN   zt d|\}}}W n& t jk
r<   td|dY nX | t|||S )z5
        Convert the bytes into an `Entity`.
        <Bqqzmalformed entity data, got N)structunpackerrorrI   r,   )rJ   Zblobr>   r?   r@   r   r   r   
from_bytes   s
    zEntity.from_bytesc                 C   s   t | j d| j d| j S )NrE   )chrr>   r?   r@   r   r   r   r   __str__   s    zEntity.__str__c                 C   s   t d| j| j| jS )NrL   )rM   packr>   r?   r@   r   r   r   r   	__bytes__   s    zEntity.__bytes__c                 C   s<   | j rt| j| jS | jtjkr*t| jS t| j| jS d S r   )	rA   r   r?   r@   r>   r,   r8   r   r   r   r   r   r   _as_input_peer   s
    
zEntity._as_input_peerc                    s   t  fdd jD S )Nc                    s   i | ]}|t  |qS r   r   r   r   r   r   r      s      z#Entity.__repr__.<locals>.<dictcomp>r   r   r   r   r   r"      s    zEntity.__repr__N)r#   r$   r%   r&   r!   r,   r'   r   propertyrA   rB   rC   classmethodstrrK   rP   rR   rT   rU   r"   r   r   r   r   r<   h   s(   




r<   )typingr   r   enumr   Ztl.typesr   r   r   rM   r	   r)   r,   r6   r7   r8   r9   r:   r;   r3   r<   r   r   r   r   <module>   s(   *      
