o
    "h-                     @   s   d Z ddlZddlmZ ddl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 ddlmZmZmZmZ ddlmZ ddlmZmZ er^d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%G dd deZ&dS )zCThis module contains objects that represent paid media in Telegram.    N)Sequence)TYPE_CHECKINGFinalOptionalUnion)	constants)	PhotoSize)Video)TelegramObject)User)enum)de_json_optionalde_list_optionalparse_sequence_argto_timedelta)get_timedelta_value)JSONDict
TimePeriod)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< 	 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 )	PaidMediaa  Describes the paid media added to a message. Currently, it can be one of:

    * :class:`telegram.PaidMediaPreview`
    * :class:`telegram.PaidMediaPhoto`
    * :class:`telegram.PaidMediaVideo`

    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:: 21.4

    Args:
        type (:obj:`str`): Type of the paid media.

    Attributes:
        type (:obj:`str`): Type of the paid media.
    )typePREVIEWPHOTOVIDEON
api_kwargsr   r   returnc                   s6   t  j|d ttj||| _| jf| _|   d S Nr   )	super__init__r   
get_memberr   PaidMediaTyper   	_id_attrs_freeze)selfr   r   	__class__ F/var/www/html/venv/lib/python3.10/site-packages/telegram/_paidmedia.pyr   H   s   
zPaidMedia.__init__databotr   c                    s   |  |}| jt| jt| jti}| tu r'|d|v r'||	d j
||dS d|v r<|d }r8tj|dnd|d< t j
||dS )aX  Converts JSON data to the appropriate :class:`PaidMedia` 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*   duration)secondsN)_parse_datar   PaidMediaPreviewr   PaidMediaPhotor   PaidMediaVideor   getpopde_jsondtm	timedeltar   )clsr)   r*   _class_mappingsr%   r'   r(   r4   T   s   
"zPaidMedia.de_jsonN)__name__
__module____qualname____doc__	__slots__r   r!   r   r   str__annotations__r   r   r   r   r   classmethodr4   __classcell__r'   r'   r%   r(   r   ,   s&   
 *r   c                       sx   e Zd ZdZdZ			ddddee dee dee dee d	df
 fd
dZ	e
d	eeeejf  fddZ  ZS )r/   a  The paid media isn't available before the payment.

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

    .. versionadded:: 21.4

    .. versionchanged:: v22.2
       As part of the migration to representing time periods using ``datetime.timedelta``,
       equality comparison now considers integer durations and equivalent timedeltas as equal.

    Args:
        type (:obj:`str`): Type of the paid media, always :tg-const:`telegram.PaidMedia.PREVIEW`.
        width (:obj:`int`, optional): Media width as defined by the sender.
        height (:obj:`int`, optional): Media height as defined by the sender.
        duration (:obj:`int` | :class:`datetime.timedelta`, optional): Duration of the media in
            seconds as defined by the sender.

            .. versionchanged:: v22.2
                |time-period-input|

    Attributes:
        type (:obj:`str`): Type of the paid media, always :tg-const:`telegram.PaidMedia.PREVIEW`.
        width (:obj:`int`): Optional. Media width as defined by the sender.
        height (:obj:`int`): Optional. Media height as defined by the sender.
        duration (:obj:`int` | :class:`datetime.timedelta`): Optional. Duration of the media in
            seconds as defined by the sender.

            .. deprecated:: v22.2
                |time-period-int-deprecated|
    )	_durationheightwidthNr   rF   rE   r,   r   r   c                   sl   t  jtj|d |   || _|| _t|| _| j	| j| j| jf| _
W d    d S 1 s/w   Y  d S N)r   r   )r   r   r   r   	_unfrozenrF   rE   r   rD   r   r"   )r$   rF   rE   r,   r   r%   r'   r(   r      s   

"zPaidMediaPreview.__init__c                 C   s   t | jddS )Nr,   )	attribute)r   rD   )r$   r'   r'   r(   r,      s   zPaidMediaPreview.duration)NNN)r;   r<   r=   r>   r?   r   intr   r   r   propertyr   r5   r6   r,   rC   r'   r'   r%   r(   r/   r   s*    !&r/   c                       sd   e Zd ZdZdZddded 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 )r0   a3  
    The paid media is a photo.

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

    .. versionadded:: 21.4

    Args:
        type (:obj:`str`): Type of the paid media, always :tg-const:`telegram.PaidMedia.PHOTO`.
        photo (Sequence[:class:`telegram.PhotoSize`]): The photo.

    Attributes:
        type (:obj:`str`): Type of the paid media, always :tg-const:`telegram.PaidMedia.PHOTO`.
        photo (tuple[:class:`telegram.PhotoSize`]): The photo.
    )photoNr   rL   r   r   r   c                   sX   t  jtj|d |   t|| _| j| jf| _W d    d S 1 s%w   Y  d S rG   )	r   r   r   r   rH   r   rL   r   r"   )r$   rL   r   r%   r'   r(   r      s
   

"zPaidMediaPhoto.__init__r)   r*   r   c                    0   |  |}t|dt||d< t j||dS )NrL   r+   )r.   r   r2   r   r   r4   r7   r)   r*   r%   r'   r(   r4         
zPaidMediaPhoto.de_jsonr:   )r;   r<   r=   r>   r?   r   r   r   r   rB   r4   rC   r'   r'   r%   r(   r0      s    *r0   c                       s`   e Zd ZdZdZ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 )r1   a  
    The paid media is a video.

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

    .. versionadded:: 21.4

    Args:
        type (:obj:`str`): Type of the paid media, always :tg-const:`telegram.PaidMedia.VIDEO`.
        video (:class:`telegram.Video`): The video.

    Attributes:
        type (:obj:`str`): Type of the paid media, always :tg-const:`telegram.PaidMedia.VIDEO`.
        video (:class:`telegram.Video`): The video.
    )videoNr   rP   r   r   c                   sT   t  jtj|d |   || _| j| jf| _W d    d S 1 s#w   Y  d S rG   )r   r   r   r   rH   rP   r   r"   )r$   rP   r   r%   r'   r(   r      s
   
"zPaidMediaVideo.__init__r)   r*   r   c                    rM   )NrP   r+   )r.   r   r2   r	   r   r4   rN   r%   r'   r(   r4      rO   zPaidMediaVideo.de_jsonr:   )r;   r<   r=   r>   r?   r	   r   r   r   rB   r4   rC   r'   r'   r%   r(   r1      s    *r1   c                	       sh   e Zd ZdZdZddd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  ZS )PaidMediaInfoa  
    Describes the paid media added to a message.

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

    .. versionadded:: 21.4

    Args:
        star_count (:obj:`int`): The number of Telegram Stars that must be paid to buy access to
            the media.
        paid_media (Sequence[:class:`telegram.PaidMedia`]): Information about the paid media.

    Attributes:
        star_count (:obj:`int`): The number of Telegram Stars that must be paid to buy access to
            the media.
        paid_media (tuple[:class:`telegram.PaidMedia`]): Information about the paid media.
    )
paid_media
star_countNr   rS   rR   r   r   c                   s8   t  j|d || _t|| _| j| jf| _|   d S r   )r   r   rS   r   rR   r"   r#   )r$   rS   rR   r   r%   r'   r(   r     s
   
zPaidMediaInfo.__init__r)   r*   r   c                    rM   )NrR   r+   )r.   r   r2   r   r   r4   rN   r%   r'   r(   r4   "  rO   zPaidMediaInfo.de_jsonr:   )r;   r<   r=   r>   r?   rJ   r   r   r   r   r   rB   r4   rC   r'   r'   r%   r(   rQ      s    *rQ   c                	       sd   e Zd ZdZdZd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 )PaidMediaPurchaseda  This object contains information about a paid media purchase.

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

    Note:
        In Python :keyword:`from` is a reserved word. Use :paramref:`from_user` instead.

    .. versionadded:: 21.6

    Args:
        from_user (:class:`telegram.User`): User who purchased the media.
        paid_media_payload (:obj:`str`): Bot-specified paid media payload.

    Attributes:
        from_user (:class:`telegram.User`): User who purchased the media.
        paid_media_payload (:obj:`str`): Bot-specified paid media payload.
    )	from_userpaid_media_payloadNr   rU   r   rV   r   r   c                   s4   t  j|d || _|| _| j| jf| _|   d S r   )r   r   rU   rV   r"   r#   )r$   rU   rV   r   r%   r'   r(   r   @  s
   zPaidMediaPurchased.__init__r)   r*   r   c                    s2   |  |}tj|d|d|d< t j||dS )Nfromr+   rU   )r.   r   r4   r3   r   rN   r%   r'   r(   r4   N  s   
zPaidMediaPurchased.de_jsonr:   )r;   r<   r=   r>   r?   r@   r   r   r   rB   r4   rC   r'   r'   r%   r(   rT   *  s    *rT   )'r>   datetimer5   collections.abcr   typingr   r   r   r   telegramr   telegram._files.photosizer   telegram._files.videor	   telegram._telegramobjectr
   telegram._userr   telegram._utilsr   telegram._utils.argumentparsingr   r   r   r   telegram._utils.datetimer   telegram._utils.typesr   r   r   r   r/   r0   r1   rQ   rT   r'   r'   r'   r(   <module>   s*   F:)),