o
    2g                     @  sX   d Z ddlmZ ddlmZ ddlmZ ddlmZ G dd	 d	eZ	G d
d deZ
dS )zProvide poll-related classes.    )annotations)Any   )cachedproperty   )PRAWBasec                   @  s$   e Zd ZdZd	ddZd	ddZdS )

PollOptiona=  Class to represent one option of a poll.

    If ``submission`` is a poll :class:`.Submission`, access the poll's options like so:

    .. code-block:: python

        poll_data = submission.poll_data

        # By index -- print the first option
        print(poll_data.options[0])

        # By ID -- print the option with ID "576797"
        print(poll_data.option("576797"))

    .. include:: ../../typical_attributes.rst

    ============== =================================================
    Attribute      Description
    ============== =================================================
    ``id``         ID of the poll option.
    ``text``       The text of the poll option.
    ``vote_count`` The number of votes the poll option has received.
    ============== =================================================

    returnstrc                 C  s   d| j dS )z?Return an object initialization representation of the instance.zPollOption(id=))idself r   O/home/garg/my-data/venv/lib/python3.10/site-packages/praw/models/reddit/poll.py__repr__&   s   zPollOption.__repr__c                 C  s   | j S )z2Return a string version of the PollData, its text.)textr   r   r   r   __str__*   s   zPollOption.__str__N)r	   r
   )__name__
__module____qualname____doc__r   r   r   r   r   r   r      s    
r   c                      s:   e Zd ZdZedddZd fd
dZdddZ  ZS )PollDataa  Class to represent poll data on a poll submission.

    If ``submission`` is a poll :class:`.Submission`, access the poll data like so:

    .. code-block:: python

        poll_data = submission.poll_data
        print(f"There are {poll_data.total_vote_count} votes total.")
        print("The options are:")
        for option in poll_data.options:
            print(f"{option} ({option.vote_count} votes)")
        print(f"I voted for {poll_data.user_selection}.")

    .. include:: ../../typical_attributes.rst

    ======================== =========================================================
    Attribute                Description
    ======================== =========================================================
    ``options``              A list of :class:`.PollOption` of the poll.
    ``total_vote_count``     The total number of votes cast in the poll.
    ``user_selection``       The poll option selected by the authenticated user
                             (possibly ``None``).
    ``voting_end_timestamp`` Time the poll voting closes, represented in `Unix Time`_.
    ======================== =========================================================

    .. _unix time: https://en.wikipedia.org/wiki/Unix_time

    r	   PollOption | Nonec                 C  s   | j du rdS | | j S )zGet the user's selection in this poll, if any.

        :returns: The user's selection as a :class:`.PollOption`, or ``None`` if there
            is no choice.

        N)_user_selectionoptionr   r   r   r   user_selectionM   s   
zPollData.user_selection	attributer
   valuer   c                   sD   |dkrt |tr fdd|D }n|dkrd}t || dS )z9Objectify the options attribute, and save user_selection.optionsc                   s   g | ]}t  j|qS r   )r   _reddit).0r   r   r   r   
<listcomp>\   s    z(PollData.__setattr__.<locals>.<listcomp>r   r   N)
isinstancelistsuper__setattr__)r   r   r   	__class__r   r   r&   Y   s
   zPollData.__setattr__	option_idr   c                 C  s2   | j D ]}|j|kr|  S qd|d}t|)zGet the option with the specified ID.

        :param option_id: The ID of a poll option, as a ``str``.

        :returns: The specified :class:`.PollOption`.

        :raises: :py:class:`KeyError` if no option exists with the specified ID.

        zNo poll option with ID .)r   r   KeyError)r   r)   r   msgr   r   r   r   a   s   


zPollData.option)r	   r   )r   r
   r   r   )r)   r
   r	   r   )	r   r   r   r   r   r   r&   r   __classcell__r   r   r'   r   r   /   s    r   N)r   
__future__r   typingr   utilr   baser   r   r   r   r   r   r   <module>   s    $