U
    gL                     @   s\  d Z ddlmZ ddlmZmZ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 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 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 )$zAThis module contains the classes for Telegram Stars transactions.    )datetime)TYPE_CHECKINGDictFinalOptionalSequenceTupleType)	constants)	PaidMedia)TelegramObject)User)enum)parse_sequence_arg)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< dde	ee dd fd	d
Zedee ed ed  d fddZ  ZS )RevenueWithdrawalStatea;  This object escribes the state of a revenue withdrawal operation. Currently, it can be one
    of:

    * :class:`telegram.RevenueWithdrawalStatePending`
    * :class:`telegram.RevenueWithdrawalStateSucceeded`
    * :class:`telegram.RevenueWithdrawalStateFailed`

    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`): The type of the state.

    Attributes:
        type (:obj:`str`): The type of the state.
    typePENDING	SUCCEEDEDFAILEDN
api_kwargsr   r   returnc                   s6   t  j|d ttj||| _| jf| _|   d S Nr   )	super__init__r   
get_memberr
   RevenueWithdrawalStateTyper   	_id_attrs_freezeselfr   r   	__class__ ;/tmp/pip-unpacked-wheel-swnnwir2/telegram/_payment/stars.pyr    C   s    
zRevenueWithdrawalState.__init__r   databotr   c                    sf   |  |}|sdS | jt| jt| jti}| tkrV|d|krV||	d j
||dS t j
||dS )a[  Converts JSON data to the appropriate :class:`RevenueWithdrawalState` object, i.e. takes
        care of selecting the correct subclass.

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

        Returns:
            The Telegram object.

        Nr   r,   r-   )_parse_datar   RevenueWithdrawalStatePendingr   RevenueWithdrawalStateSucceededr   RevenueWithdrawalStateFailedr   getpopde_jsonr   clsr,   r-   Z_class_mappingr'   r)   r*   r5   J   s    
   zRevenueWithdrawalState.de_json)N)__name__
__module____qualname____doc__	__slots__r
   r"   r   r   str__annotations__r   r   r   r   r    classmethodr5   __classcell__r)   r)   r'   r*   r   &   s   
   r   c                       s6   e Zd ZdZdZddee dd fddZ  ZS )r0   zThe withdrawal is in progress.

    .. versionadded:: 21.4

    Attributes:
        type (:obj:`str`): The type of the state, always
            :tg-const:`telegram.RevenueWithdrawalState.PENDING`.
    r)   Nr   r   r   c                   s   t  jtj|d |   d S N)r   r   )r   r    r   r   r$   r&   r   r'   r)   r*   r    v   s    z&RevenueWithdrawalStatePending.__init__	r8   r9   r:   r;   r<   r   r   r    r@   r)   r)   r'   r*   r0   j   s   	r0   c                       sb   e Zd ZdZdZddeeee dd fddZ	e
dee ed ed  d	 fd
dZ  ZS )r1   a  The withdrawal succeeded.

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

    .. versionadded:: 21.4

    Args:
        date (:obj:`datetime.datetime`): Date the withdrawal was completed as a datetime object.
        url (:obj:`str`): An HTTPS URL that can be used to see transaction details.

    Attributes:
        type (:obj:`str`): The type of the state, always
            :tg-const:`telegram.RevenueWithdrawalState.SUCCEEDED`.
        date (:obj:`datetime.datetime`): Date the withdrawal was completed as a datetime object.
        url (:obj:`str`): An HTTPS URL that can be used to see transaction details.
    )dateurlNr   )rE   rF   r   r   c             	      sD   t  jtj|d |    || _|| _| j| jf| _W 5 Q R X d S rB   )	r   r    r   r   	_unfrozenrE   rF   r   r#   )r&   rE   rF   r   r'   r)   r*   r       s    
z(RevenueWithdrawalStateSucceeded.__init__r   r+   c                    sB   |  |}|sdS t|}t|dd|d|d< t j||dS )z4See :meth:`telegram.RevenueWithdrawalState.de_json`.NrE   tzinfor.   )r/   r   r   r3   r   r5   r7   r,   r-   Z
loc_tzinfor'   r)   r*   r5      s    
z'RevenueWithdrawalStateSucceeded.de_json)N)r8   r9   r:   r;   r<   r   r=   r   r   r    r?   r5   r@   r)   r)   r'   r*   r1   {   s      r1   c                       s6   e Zd ZdZdZddee dd fddZ  ZS )r2   zThe withdrawal failed and the transaction was refunded.

    .. versionadded:: 21.4

    Attributes:
        type (:obj:`str`): The type of the state, always
            :tg-const:`telegram.RevenueWithdrawalState.FAILED`.
    r)   Nr   rA   c                   s   t  jtj|d |   d S rB   )r   r    r   r   r$   rC   r'   r)   r*   r       s    z%RevenueWithdrawalStateFailed.__init__rD   r)   r)   r'   r*   r2      s   	r2   c                       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e dd	 fd
dZedee ed ed  d fddZ  ZS )TransactionPartnerau  This object describes the source of a transaction, or its recipient for outgoing
    transactions. Currently, it can be one of:

    * :class:`TransactionPartnerUser`
    * :class:`TransactionPartnerFragment`
    * :class:`TransactionPartnerTelegramAds`
    * :class:`TransactionPartnerOther`

    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`): The type of the transaction partner.

    Attributes:
        type (:obj:`str`): The type of the transaction partner.
    r   FRAGMENTUSEROTHERTELEGRAM_ADSNr   r   c                   s6   t  j|d ttj||| _| jf| _|   d S r   )	r   r    r   r!   r
   TransactionPartnerTyper   r#   r$   r%   r'   r)   r*   r       s    
zTransactionPartner.__init__r   r+   c                    s   |  |}|dkrdS |s&| tkr&dS | jt| jt| jt| jt	i}| tkrp|
d|krp||d j||dS t j||dS )aW  Converts JSON data to the appropriate :class:`TransactionPartner` object, i.e. takes
        care of selecting the correct subclass.

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

        Returns:
            The Telegram object.

        Nr   r.   )r/   rK   rL   TransactionPartnerFragmentrM   TransactionPartnerUserrN   TransactionPartnerOtherrO   TransactionPartnerTelegramAdsr3   r4   r5   r   r6   r'   r)   r*   r5      s"    
    zTransactionPartner.de_json)N)r8   r9   r:   r;   r<   r
   rP   rL   r   r=   r>   rM   rN   rO   r   r   r    r?   r5   r@   r)   r)   r'   r*   rK      s   
   rK   c                       sf   e Zd ZdZdZddded ee dd fddZedee ed	 ed  d
 fddZ	  Z
S )rQ   a  Describes a withdrawal transaction with Fragment.

    .. versionadded:: 21.4

    Args:
        withdrawal_state (:class:`telegram.RevenueWithdrawalState`, optional): State of the
            transaction if the transaction is outgoing.

    Attributes:
        type (:obj:`str`): The type of the transaction partner,
            always :tg-const:`telegram.TransactionPartner.FRAGMENT`.
        withdrawal_state (:class:`telegram.RevenueWithdrawalState`): Optional. State of the
            transaction if the transaction is outgoing.
    )withdrawal_stateNr   r   )rU   r   r   c             	      s0   t  jtj|d |   || _W 5 Q R X d S rB   )r   r    rK   rL   rG   rU   )r&   rU   r   r'   r)   r*   r       s    
z#TransactionPartnerFragment.__init__r   r+   c                    s8   |  |}|sdS t|d||d< t j||dS )0See :meth:`telegram.TransactionPartner.de_json`.NrU   r.   )r/   r   r5   r3   r   r7   r,   r-   r'   r)   r*   r5   +  s    
 z"TransactionPartnerFragment.de_json)N)N)r8   r9   r:   r;   r<   r   r   r    r?   r5   r@   r)   r)   r'   r*   rQ     s"      rQ   c                	       sx   e Zd ZdZdZddddee eee  ee ee	 dd fddZ
edee	 ed	 ed  d
 fddZ  ZS )rR   a  Describes a transaction with a user.

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

    .. versionadded:: 21.4

    Args:
        user (:class:`telegram.User`): Information about the user.
        invoice_payload (:obj:`str`, optional): Bot-specified invoice payload.
        paid_media (Sequence[:class:`telegram.PaidMedia`], optional): Information about the paid
            media bought by the user.

            .. versionadded:: 21.5
        paid_media_payload (:obj:`str`, optional): Optional. Bot-specified paid media payload.

            .. versionadded:: 21.6

    Attributes:
        type (:obj:`str`): The type of the transaction partner,
            always :tg-const:`telegram.TransactionPartner.USER`.
        user (:class:`telegram.User`): Information about the user.
        invoice_payload (:obj:`str`): Optional. Bot-specified invoice payload.
        paid_media (Tuple[:class:`telegram.PaidMedia`]): Optional. Information about the paid
            media bought by the user.

            .. versionadded:: 21.5
        paid_media_payload (:obj:`str`): Optional. Optional. Bot-specified paid media payload.

            .. versionadded:: 21.6

    )invoice_payload
paid_mediapaid_media_payloaduserNr   r   )r[   rX   rY   rZ   r   r   c             	      sT   t  jtj|d |  0 || _|| _t|| _|| _	| j
| jf| _W 5 Q R X d S rB   )r   r    rK   rM   rG   r[   rX   r   rY   rZ   r   r#   )r&   r[   rX   rY   rZ   r   r'   r)   r*   r    `  s    	

zTransactionPartnerUser.__init__r   r+   c                    sP   |  |}|sdS t|d||d< tj|d|d|d< t j||dS )rV   Nr[   rY   )r-   r.   )r/   r   r5   r3   r   de_listr   rW   r'   r)   r*   r5   u  s    
zTransactionPartnerUser.de_json)NNN)N)r8   r9   r:   r;   r<   r   r=   r   r   r   r    r?   r5   r@   r)   r)   r'   r*   rR   <  s,   !   
  rR   c                       s6   e Zd ZdZdZddee dd fddZ  ZS )rS   zDescribes a transaction with an unknown partner.

    .. versionadded:: 21.4

    Attributes:
        type (:obj:`str`): The type of the transaction partner,
            always :tg-const:`telegram.TransactionPartner.OTHER`.
    r)   Nr   rA   c                   s   t  jtj|d |   d S rB   )r   r    rK   rN   r$   rC   r'   r)   r*   r      s    z TransactionPartnerOther.__init__rD   r)   r)   r'   r*   rS     s   	rS   c                       s6   e Zd ZdZdZddee dd fddZ  ZS )rT   zDescribes a withdrawal transaction to the Telegram Ads platform.

    .. versionadded:: 21.4

    Attributes:
        type (:obj:`str`): The type of the transaction partner,
            always :tg-const:`telegram.TransactionPartner.TELEGRAM_ADS`.
    r)   Nr   rA   c                   s   t  jtj|d |   d S rB   )r   r    rK   rO   r$   rC   r'   r)   r*   r      s    z&TransactionPartnerTelegramAds.__init__rD   r)   r)   r'   r*   rT     s   	rT   c                
       sr   e Zd ZdZdZdddeeeee	 ee	 ee
 dd fddZedee
 ed ed  d	 fd
dZ  ZS )StarTransactionat  Describes a Telegram Star transaction.

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

    .. versionadded:: 21.4

    Args:
        id (:obj:`str`): Unique identifier of the transaction. Coincides with the identifer
            of the original transaction for refund transactions.
            Coincides with :attr:`SuccessfulPayment.telegram_payment_charge_id` for
            successful incoming payments from users.
        amount (:obj:`int`): Number of Telegram Stars transferred by the transaction.
        date (:obj:`datetime.datetime`): Date the transaction was created as a datetime object.
        source (:class:`telegram.TransactionPartner`, optional): Source of an incoming transaction
            (e.g., a user purchasing goods or services, Fragment refunding a failed withdrawal).
            Only for incoming transactions.
        receiver (:class:`telegram.TransactionPartner`, optional): Receiver of an outgoing
            transaction (e.g., a user for a purchase refund, Fragment for a withdrawal). Only for
            outgoing transactions.

    Attributes:
        id (:obj:`str`): Unique identifier of the transaction. Coincides with the identifer
            of the original transaction for refund transactions.
            Coincides with :attr:`SuccessfulPayment.telegram_payment_charge_id` for
            successful incoming payments from users.
        amount (:obj:`int`): Number of Telegram Stars transferred by the transaction.
        date (:obj:`datetime.datetime`): Date the transaction was created as a datetime object.
        source (:class:`telegram.TransactionPartner`): Optional. Source of an incoming transaction
            (e.g., a user purchasing goods or services, Fragment refunding a failed withdrawal).
            Only for incoming transactions.
        receiver (:class:`telegram.TransactionPartner`): Optional. Receiver of an outgoing
            transaction (e.g., a user for a purchase refund, Fragment for a withdrawal). Only for
            outgoing transactions.
    )amountrE   idreceiversourceNr   )r_   r^   rE   ra   r`   r   r   c                   sJ   t  j|d || _|| _|| _|| _|| _| j| j| jf| _|   d S r   )	r   r    r_   r^   rE   ra   r`   r#   r$   )r&   r_   r^   rE   ra   r`   r   r'   r)   r*   r      s    
zStarTransaction.__init__r   r+   c                    sn   |  |}|sdS t|}t|dd|d|d< t|d||d< t|d||d< t j||dS ),See :meth:`telegram.TelegramObject.de_json`.NrE   rH   ra   r`   r.   )r/   r   r   r3   rK   r5   r   rJ   r'   r)   r*   r5     s    
zStarTransaction.de_json)NN)N)r8   r9   r:   r;   r<   r=   intr   r   rK   r   r    r?   r5   r@   r)   r)   r'   r*   r]     s,   $    r]   c                       sb   e Zd ZdZdZddee ee d fddZ	e
dee ed ed  d	 fd
dZ  ZS )StarTransactionsa  
    Contains a list of Telegram Star transactions.

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

    .. versionadded:: 21.4

    Args:
        transactions (Sequence[:class:`telegram.StarTransaction`]): The list of transactions.

    Attributes:
        transactions (Tuple[:class:`telegram.StarTransaction`]): The list of transactions.
    )transactionsNr   )re   r   c                   s.   t  j|d t|| _| jf| _|   d S r   )r   r    r   re   r#   r$   )r&   re   r   r'   r)   r*   r      s    

zStarTransactions.__init__r   r+   c                    s<   |  |}|dkrdS t|d||d< t j||dS )rb   Nre   r.   )r/   r]   r\   r3   r   r5   rW   r'   r)   r*   r5     s
    
zStarTransactions.de_json)N)r8   r9   r:   r;   r<   r   r]   r   r   r    r?   r5   r@   r)   r)   r'   r*   rd     s    	  rd   N)'r;   r   typingr   r   r   r   r   r   r	   Ztelegramr
   Ztelegram._paidmediar   Ztelegram._telegramobjectr   Ztelegram._userr   Ztelegram._utilsr   Ztelegram._utils.argumentparsingr   Ztelegram._utils.datetimer   r   Ztelegram._utils.typesr   r   r   r0   r1   r2   rK   rQ   rR   rS   rT   r]   rd   r)   r)   r)   r*   <module>   s.   $D7K.IS