o
    "hJ                     @   s  d Z ddlZddlmZ ddl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 ddlmZ ddlmZmZmZ ddlmZmZ ddlmZm Z  ddl!m"Z" erhd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'dS )z8This module contains objects that represent owned gifts.    N)Sequence)TYPE_CHECKINGFinalOptional)	constants)Gift)MessageEntity)TelegramObject)
UniqueGift)User)enum)de_json_optionalde_list_optionalparse_sequence_arg)extract_tzinfo_from_defaultsfrom_timestamp)parse_message_entitiesparse_message_entity)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< 	 ddde	dee d	df fd
dZeddeded d	d f fddZ  ZS )	OwnedGifta  This object describes a gift received and owned by a user or a chat. Currently, it
    can be one of:

    * :class:`telegram.OwnedGiftRegular`
    * :class:`telegram.OwnedGiftUnique`

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

    .. versionadded:: 22.1

    Args:
        type (:obj:`str`): Type of the owned gift.

    Attributes:
        type (:obj:`str`): Type of the owned gift.
    )typeREGULARUNIQUEN
api_kwargsr   r   returnc                   s6   t  j|d ttj||| _| jf| _|   d S Nr   )	super__init__r   
get_memberr   OwnedGiftTyper   	_id_attrs_freeze)selfr   r   	__class__ F/var/www/html/venv/lib/python3.10/site-packages/telegram/_ownedgift.pyr   C   s   
zOwnedGift.__init__databotr   c                    sX   |  |}| jt| jti}| tu r$|d|v r$||d j||dS t	 j||dS )aX  Converts JSON data to the appropriate :class:`OwnedGift` object, i.e. takes
        care of selecting the correct subclass.

        Args:
            data (dict[:obj:`str`, ...]): The JSON data.
            bot (:class:`telegram.Bot`, optional): The bot associated with this object.

        Returns:
            The Telegram object.

        r   r)   r*   )
_parse_datar   OwnedGiftRegularr   OwnedGiftUniquer   getpopde_jsonr   )clsr)   r*   _class_mappingr%   r'   r(   r1   O   s   
zOwnedGift.de_jsonN)__name__
__module____qualname____doc__	__slots__r   r!   r   r   str__annotations__r   r   r   r   classmethodr1   __classcell__r'   r'   r%   r(   r   )   s"   
 *r   c                       sp   e Zd ZdZdZ	ddddedee dee	 dee
 f fd	d
Zedde
ded dd f fddZ  ZS )
OwnedGiftsau  Contains the list of gifts received and owned by a user or a chat.

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

    .. versionadded:: 22.1

    Args:
        total_count (:obj:`int`): The total number of gifts owned by the user or the chat.
        gifts (Sequence[:class:`telegram.OwnedGift`]): The list of gifts.
        next_offset (:obj:`str`, optional): Offset for the next request. If empty,
            then there are no more results.

    Attributes:
        total_count (:obj:`int`): The total number of gifts owned by the user or the chat.
        gifts (Sequence[:class:`telegram.OwnedGift`]): The list of gifts.
        next_offset (:obj:`str`): Optional. Offset for the next request. If empty,
            then there are no more results.
    )giftsnext_offsettotal_countNr   rA   r?   r@   r   c                   s>   t  j|d || _t|| _|| _| j| jf| _|   d S r   )r   r   rA   r   r?   r@   r"   r#   )r$   rA   r?   r@   r   r%   r'   r(   r      s   
zOwnedGifts.__init__r)   r*   r   r   c                    s0   |  |}t|dt||d< t j||dS )z,See :meth:`telegram.TelegramObject.de_json`.r?   r+   )r,   r   r/   r   r   r1   )r2   r)   r*   r%   r'   r(   r1      s   
zOwnedGifts.de_jsonr4   )r5   r6   r7   r8   r9   intr   r   r   r:   r   r   r<   r1   r=   r'   r'   r%   r(   r>   i   s"    
*r>   c                       s  e Zd ZdZdZ										d dddedejdee	 dee
 d	ee	 d
eee  dee dee dee dee dee dee dee ddf fddZed!deded dd f fddZdede	fddZd!deee	  deee	f fddZ  ZS )"r-   a  Describes a regular gift owned by a user or a chat.

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

    .. versionadded:: 22.1

    Args:
        gift (:class:`telegram.Gift`): Information about the regular gift.
        owned_gift_id (:obj:`str`, optional): Unique identifier of the gift for the bot; for
            gifts received on behalf of business accounts only.
        sender_user (:class:`telegram.User`, optional): Sender of the gift if it is a known user.
        send_date (:obj:`datetime.datetime`): Date the gift was sent as :class:`datetime.datetime`.
            |datetime_localization|.
        text (:obj:`str`, optional): Text of the message that was added to the gift.
        entities (Sequence[:class:`telegram.MessageEntity`], optional): Special entities that
            appear in the text.
        is_private (:obj:`bool`, optional): :obj:`True`, if the sender and gift text are shown
            only to the gift receiver; otherwise, everyone will be able to see them.
        is_saved (:obj:`bool`, optional): :obj:`True`, if the gift is displayed on the account's
            profile page; for gifts received on behalf of business accounts only.
        can_be_upgraded (:obj:`bool`, optional): :obj:`True`, if the gift can be upgraded to a
            unique gift; for gifts received on behalf of business accounts only.
        was_refunded (:obj:`bool`, optional): :obj:`True`, if the gift was refunded and isn't
            available anymore.
        convert_star_count (:obj:`int`, optional): Number of Telegram Stars that can be
            claimed by the receiver instead of the gift; omitted if the gift cannot be converted
            to Telegram Stars.
        prepaid_upgrade_star_count (:obj:`int`, optional): Number of Telegram Stars that were
            paid by the sender for the ability to upgrade the gift.

    Attributes:
        type (:obj:`str`): Type of the gift, always :attr:`~telegram.OwnedGift.REGULAR`.
        gift (:class:`telegram.Gift`): Information about the regular gift.
        owned_gift_id (:obj:`str`): Optional. Unique identifier of the gift for the bot; for
            gifts received on behalf of business accounts only.
        sender_user (:class:`telegram.User`): Optional. Sender of the gift if it is a known user.
        send_date (:obj:`datetime.datetime`): Date the gift was sent as :class:`datetime.datetime`.
            |datetime_localization|.
        text (:obj:`str`): Optional. Text of the message that was added to the gift.
        entities (Sequence[:class:`telegram.MessageEntity`]): Optional. Special entities that
            appear in the text.
        is_private (:obj:`bool`): Optional. :obj:`True`, if the sender and gift text are shown
            only to the gift receiver; otherwise, everyone will be able to see them.
        is_saved (:obj:`bool`): Optional. :obj:`True`, if the gift is displayed on the account's
            profile page; for gifts received on behalf of business accounts only.
        can_be_upgraded (:obj:`bool`): Optional. :obj:`True`, if the gift can be upgraded to a
            unique gift; for gifts received on behalf of business accounts only.
        was_refunded (:obj:`bool`): Optional. :obj:`True`, if the gift was refunded and isn't
            available anymore.
        convert_star_count (:obj:`int`): Optional. Number of Telegram Stars that can be
            claimed by the receiver instead of the gift; omitted if the gift cannot be converted
            to Telegram Stars.
        prepaid_upgrade_star_count (:obj:`int`): Optional. Number of Telegram Stars that were
            paid by the sender for the ability to upgrade the gift.

    )can_be_upgradedconvert_star_countentitiesgift
is_privateis_savedowned_gift_idprepaid_upgrade_star_count	send_datesender_usertextwas_refundedNr   rF   rK   rI   rL   rM   rE   rG   rH   rC   rN   rD   rJ   r   r   c                   s   t  jtj|d |  8 || _|| _|| _|| _|| _	t
|| _|| _|| _|	| _|
| _|| _|| _| j| j| jf| _W d    d S 1 sHw   Y  d S N)r   r   )r   r   r   r   	_unfrozenrF   rK   rI   rL   rM   r   rE   rG   rH   rC   rN   rD   rJ   r   r"   )r$   rF   rK   rI   rL   rM   rE   rG   rH   rC   rN   rD   rJ   r   r%   r'   r(   r      s    

"zOwnedGiftRegular.__init__r)   r*   r   c                    sz   |  |}t|}t|d|d|d< t|dt||d< t|dt||d< t|dt||d< t	 j
||dS )'See :meth:`telegram.OwnedGift.de_json`.rK   tzinforL   rF   rE   r+   )r,   r   r   r/   r   r   r   r   r   r   r1   r2   r)   r*   
loc_tzinfor%   r'   r(   r1     s   
zOwnedGiftRegular.de_jsonentityc                 C   s   | j stdt| j |S )a  Returns the text in :attr:`text`
        from a given :class:`telegram.MessageEntity` of :attr:`entities`.

        Note:
            This method is present because Telegram calculates the offset and length in
            UTF-16 codepoint pairs, which some versions of Python don't handle automatically.
            (That is, you can't just slice ``OwnedGiftRegular.text`` with the offset and length.)

        Args:
            entity (:class:`telegram.MessageEntity`): The entity to extract the text from. It must
                be an entity that belongs to :attr:`entities`.

        Returns:
            :obj:`str`: The text of the given entity.

        Raises:
            RuntimeError: If the owned gift has no text.

        $This OwnedGiftRegular has no 'text'.)rM   RuntimeErrorr   )r$   rV   r'   r'   r(   parse_entity  s   zOwnedGiftRegular.parse_entitytypesc                 C   s   | j stdt| j | j|S )aQ  
        Returns a :obj:`dict` that maps :class:`telegram.MessageEntity` to :obj:`str`.
        It contains entities from this owned gift's text filtered by their ``type`` attribute as
        the key, and the text that each entity belongs to as the value of the :obj:`dict`.

        Note:
            This method should always be used instead of the :attr:`entities`
            attribute, since it calculates the correct substring from the message text based on
            UTF-16 codepoints. See :attr:`parse_entity` for more info.

        Args:
            types (list[:obj:`str`], optional): List of ``MessageEntity`` types as strings. If the
                    ``type`` attribute of an entity is contained in this list, it will be returned.
                    Defaults to :attr:`telegram.MessageEntity.ALL_TYPES`.

        Returns:
            dict[:class:`telegram.MessageEntity`, :obj:`str`]: A dictionary of entities mapped to
            the text that belongs to them, calculated based on UTF-16 codepoints.

        Raises:
            RuntimeError: If the owned gift has no text.

        rW   )rM   rX   r   rE   )r$   rZ   r'   r'   r(   parse_entities1  s   zOwnedGiftRegular.parse_entities)
NNNNNNNNNNr4   )r5   r6   r7   r8   r9   r   dtmdatetimer   r:   r   r   r   boolrB   r   r   r<   r1   rY   listdictr[   r=   r'   r'   r%   r(   r-      s`    :
	
#",r-   c                       s   e Zd ZdZdZ						ddddedejdee	 dee
 d	ee d
ee dee deej dee ddf fddZeddeded dd f fddZ  ZS )r.   ah  
    Describes a unique gift received and owned by a user or a chat.

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

    .. versionadded:: 22.1

    Args:
        gift (:class:`telegram.UniqueGift`): Information about the unique gift.
        owned_gift_id (:obj:`str`, optional): Unique identifier of the received gift for the
            bot; for gifts received on behalf of business accounts only.
        sender_user (:class:`telegram.User`, optional): Sender of the gift if it is a known user.
        send_date (:obj:`datetime.datetime`): Date the gift was sent as :class:`datetime.datetime`.
            |datetime_localization|
        is_saved (:obj:`bool`, optional): :obj:`True`, if the gift is displayed on the account's
            profile page; for gifts received on behalf of business accounts only.
        can_be_transferred (:obj:`bool`, optional): :obj:`True`, if the gift can be transferred to
            another owner; for gifts received on behalf of business accounts only.
        transfer_star_count (:obj:`int`, optional): Number of Telegram Stars that must be paid
            to transfer the gift; omitted if the bot cannot transfer the gift.
        next_transfer_date (:obj:`datetime.datetime`, optional): Date when the gift can be
            transferred. If it's in the past, then the gift can be transferred now.
            |datetime_localization|
            .. versionadded:: 22.3

    Attributes:
        type (:obj:`str`): Type of the owned gift, always :tg-const:`~telegram.OwnedGift.UNIQUE`.
        gift (:class:`telegram.UniqueGift`): Information about the unique gift.
        owned_gift_id (:obj:`str`): Optional. Unique identifier of the received gift for the
            bot; for gifts received on behalf of business accounts only.
        sender_user (:class:`telegram.User`): Optional. Sender of the gift if it is a known user.
        send_date (:obj:`datetime.datetime`): Date the gift was sent as :class:`datetime.datetime`.
            |datetime_localization|
        is_saved (:obj:`bool`): Optional. :obj:`True`, if the gift is displayed on the account's
            profile page; for gifts received on behalf of business accounts only.
        can_be_transferred (:obj:`bool`): Optional. :obj:`True`, if the gift can be transferred to
            another owner; for gifts received on behalf of business accounts only.
        transfer_star_count (:obj:`int`): Optional. Number of Telegram Stars that must be paid
            to transfer the gift; omitted if the bot cannot transfer the gift.
        next_transfer_date (:obj:`datetime.datetime`): Optional. Date when the gift can be
            transferred. If it's in the past, then the gift can be transferred now.
            |datetime_localization|
            .. versionadded:: 22.3
    )can_be_transferredrF   rH   next_transfer_daterI   rK   rL   transfer_star_countNr   rF   rK   rI   rL   rH   ra   rc   rb   r   r   c	          
         s   t  jtj|	d |  * || _|| _|| _|| _|| _	|| _
|| _|| _| j| j| jf| _W d    d S 1 s:w   Y  d S rO   )r   r   r   r   rP   rF   rK   rI   rL   rH   ra   rc   rb   r   r"   )
r$   rF   rK   rI   rL   rH   ra   rc   rb   r   r%   r'   r(   r     s   
"zOwnedGiftUnique.__init__r)   r*   r   c                    sz   |  |}t|}t|d|d|d< t|dt||d< t|dt||d< t|d|d|d< t j||dS )rQ   rK   rR   rL   rF   rb   r+   )	r,   r   r   r/   r   r   r
   r   r1   rT   r%   r'   r(   r1     s   


zOwnedGiftUnique.de_json)NNNNNNr4   )r5   r6   r7   r8   r9   r
   r\   r]   r   r:   r   r^   rB   r   r   r<   r1   r=   r'   r'   r%   r(   r.   O  sD    .	*r.   )(r8   r]   r\   collections.abcr   typingr   r   r   telegramr   telegram._giftsr   telegram._messageentityr   telegram._telegramobjectr	   telegram._uniquegiftr
   telegram._userr   telegram._utilsr   telegram._utils.argumentparsingr   r   r   telegram._utils.datetimer   r   telegram._utils.entitiesr   r   telegram._utils.typesr   r   r   r>   r-   r.   r'   r'   r'   r(   <module>   s,   @5 2