o
    2g4                     @  s   d 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
 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 erDddl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 )zProvide the helper classes.    )annotations)dumps)TYPE_CHECKINGAny	Generator   )API_PATH)_deprecate_args   )PRAWBase)Draft)
LiveThread)Multireddit	SubredditNc                   @  sL   e Zd ZdZ	d!d"ddZd#d
dZddddddddddddd$dd ZdS )%DraftHelperzProvide a set of functions to interact with :class:`.Draft` instances.

    .. note::

        The methods provided by this class will only work on the currently authenticated
        user's :class:`.Draft`\ s.

    Ndraft_id
str | Nonereturn+list[praw.models.Draft] | praw.models.Draftc                 C  s   |durt | j|dS |  S )a  Return a list of :class:`.Draft` instances.

        :param draft_id: When provided, this returns a :class:`.Draft` instance
            (default: ``None``).

        :returns: A :class:`.Draft` instance if ``draft_id`` is provided. Otherwise, a
            list of :class:`.Draft` objects.

        .. note::

            Drafts fetched using a specific draft ID are lazily loaded, so you might
            have to access an attribute to get all the expected attributes.

        This method can be used to fetch a specific draft by ID, like so:

        .. code-block:: python

            draft_id = "124862bc-e1e9-11eb-aa4f-e68667a77cbb"
            draft = reddit.drafts(draft_id)
            print(draft)

        Nid)r   _reddit_draft_list)selfr    r   K/home/garg/my-data/venv/lib/python3.10/site-packages/praw/models/helpers.py__call__   s   zDraftHelper.__call__list[praw.models.Draft]c                 C  s   | j jtd ddidS )zjGet a list of :class:`.Draft` instances.

        :returns: A list of :class:`.Draft` instances.

        draftsmd_bodyTparamsr   getr   r   r   r   r   r   :   s   zDraftHelper._draft_listFTflair_id
flair_textis_public_linknsfworiginal_contentselftextsend_repliesspoiler	subreddittitleurlr&   r'   r(   boolr)   r*   r+   r,   r-   r.   >str | praw.models.Subreddit | praw.models.UserSubreddit | Noner/   r0   draft_kwargsr   praw.models.Draftc                K  sf   |r
|r
d}t |t|	tr| j|	}	tjd|||||||||	|
|d|}| jjtd |dS )aa  Create a new :class:`.Draft`.

        :param flair_id: The flair template to select (default: ``None``).
        :param flair_text: If the template's ``flair_text_editable`` value is ``True``,
            this value will set a custom text (default: ``None``). ``flair_id`` is
            required when ``flair_text`` is provided.
        :param is_public_link: Whether to enable public viewing of the draft before it
            is submitted (default: ``False``).
        :param nsfw: Whether the draft should be marked NSFW (default: ``False``).
        :param original_content: Whether the submission should be marked as original
            content (default: ``False``).
        :param selftext: The Markdown formatted content for a text submission draft. Use
            ``None`` to make a title-only submission draft (default: ``None``).
            ``selftext`` can not be provided if ``url`` is provided.
        :param send_replies: When ``True``, messages will be sent to the submission
            author when comments are made to the submission (default: ``True``).
        :param spoiler: Whether the submission should be marked as a spoiler (default:
            ``False``).
        :param subreddit: The subreddit to create the draft for. This accepts a
            subreddit display name, :class:`.Subreddit` object, or
            :class:`.UserSubreddit` object. If ``None``, the :class:`.UserSubreddit` of
            currently authenticated user will be used (default: ``None``).
        :param title: The title of the draft (default: ``None``).
        :param url: The URL for a ``link`` submission draft (default: ``None``). ``url``
            can not be provided if ``selftext`` is provided.

        Additional keyword arguments can be provided to handle new parameters as Reddit
        introduces them.

        :returns: The new :class:`.Draft` object.

        z4Exactly one of 'selftext' or 'url' must be provided.r%   draftdataNr   )		TypeError
isinstancestrr   r.   r   _prepare_datapostr   )r   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r3   msgr7   r   r   r   createB   s*   2
zDraftHelper.create)N)r   r   r   r   )r   r   )r&   r   r'   r   r(   r1   r)   r1   r*   r1   r+   r   r,   r1   r-   r1   r.   r2   r/   r   r0   r   r3   r   r   r4   )__name__
__module____qualname____doc__r   r   r>   r   r   r   r   r      s"    

r   c                   @  sP   e Zd ZdZdddZedd	d
ddddddddZdddZdddZdS )
LiveHelperzDProvide a set of functions to interact with :class:`.LiveThread`\ s.r   r:   r   praw.models.LiveThreadc                 C  s   t | j|dS )a  Return a new lazy instance of :class:`.LiveThread`.

        This method is intended to be used as:

        .. code-block:: python

            livethread = reddit.live("ukaeu1ik4sw5")

        :param id: A live thread ID, e.g., ``ukaeu1ik4sw5``.

        r   )r   r   )r   r   r   r   r   r      s   zLiveHelper.__call__r/   descriptionr)   	resourcesNF)rE   r)   rF   r   r1   c                C  s   | j jtd ||||ddS )a  Create a new :class:`.LiveThread`.

        :param title: The title of the new :class:`.LiveThread`.
        :param description: The new :class:`.LiveThread`'s description.
        :param nsfw: Indicate whether this thread is not safe for work (default:
            ``False``).
        :param resources: Markdown formatted information that is useful for the
            :class:`.LiveThread`.

        :returns: The new :class:`.LiveThread` object.

        
livecreate)rE   r)   rF   r/   r6   )r   r<   r   )r   r/   rE   r)   rF   r   r   r   r>      s   zLiveHelper.createids	list[str]-Generator[praw.models.LiveThread, None, None]c                   s*   t  tsd}t| fdd}| S )a  Fetch information about each live thread in ``ids``.

        :param ids: A list of IDs for a live thread.

        :returns: A generator that yields :class:`.LiveThread` instances.

        :raises: ``prawcore.ServerError`` if invalid live threads are requested.

        Requests will be issued in batches for each 100 IDs.

        .. note::

            This method doesn't support IDs for live updates.

        .. warning::

            Unlike :meth:`.Reddit.info`, the output of this method may not reflect the
            order of input.

        Usage:

        .. code-block:: python

            ids = ["3rgnbke2rai6hen7ciytwcxadi", "sw7bubeycai6hey4ciytwamw3a", "t8jnufucss07"]
            for thread in reddit.live.info(ids):
                print(thread.title)

        zids must be a listc                  3  s`    t dt dD ]$}  | | d  }td jd|d}ddi}jj||dE d H  q	d S )Nr   d   	live_info,)rH   limitr    )rangelenr   formatjoinr   r#   )position	ids_chunkr0   r!   rH   r   r   r   	generator   s   z"LiveHelper.info.<locals>.generator)r9   listr8   )r   rH   r=   rV   r   rU   r   info   s
   
zLiveHelper.infopraw.models.LiveThread | Nonec                 C  s   | j td S )a!  Get the currently featured live thread.

        :returns: The :class:`.LiveThread` object, or ``None`` if there is no currently
            featured live thread.

        Usage:

        .. code-block:: python

            thread = reddit.live.now()  # LiveThread object or None

        live_nowr"   r$   r   r   r   now   s   zLiveHelper.now)r   r:   r   rD   )
r/   r:   rE   r   r)   r1   rF   r:   r   rD   )rH   rI   r   rJ   )r   rY   )	r?   r@   rA   rB   r   r	   r>   rX   r[   r   r   r   r   rC      s    

*rC   c                   @  sP   e Zd ZdZeddddd	Zed
dddddddddddddddZdS )MultiredditHelperz9Provide a set of functions to interact with multireddits.redditornamer:   str | praw.models.Redditorr   praw.models.Multiredditc                C  s$   d| d| }t | j||ddS )zReturn a lazy instance of :class:`.Multireddit`.

        :param name: The name of the multireddit.
        :param redditor: A redditor name or :class:`.Redditor` instance who owns the
            multireddit.

        z/user/z/m/)r^   path)_data)r   r   )r   r^   r]   ra   r   r   r   r      s   zMultiredditHelper.__call__display_name
subredditsdescription_md	icon_name	key_color
visibilityweighting_schemeNprivateclassic)re   rf   rg   rh   ri   r   str | praw.models.Subredditc          	      C  s:   ||||dd |D ||d}| j jtd dt|idS )a;  Create a new :class:`.Multireddit`.

        :param display_name: The display name for the new multireddit.
        :param subreddits: Subreddits to add to the new multireddit. Can be a list of
            either :class:`.Subreddit` instances or subreddit display names.
        :param description_md: Description for the new multireddit, formatted in
            markdown.
        :param icon_name: Can be one of: ``"art and design"``, ``"ask"``, ``"books"``,
            ``"business"``, ``"cars"``, ``"comics"``, ``"cute animals"``, ``"diy"``,
            ``"entertainment"``, ``"food and drink"``, ``"funny"``, ``"games"``,
            ``"grooming"``, ``"health"``, ``"life advice"``, ``"military"``, ``"models
            pinup"``, ``"music"``, ``"news"``, ``"philosophy"``, ``"pictures and
            gifs"``, ``"science"``, ``"shopping"``, ``"sports"``, ``"style"``,
            ``"tech"``, ``"travel"``, ``"unusual stories"``, ``"video"``, or ``None``.
        :param key_color: RGB hex color code of the form ``"#FFFFFF"``.
        :param visibility: Can be one of: ``"hidden"``, ``"private"``, or ``"public"``
            (default: ``"private"``).
        :param weighting_scheme: Can be one of: ``"classic"`` or ``"fresh"`` (default:
            ``"classic"``).

        :returns: The new :class:`.Multireddit` object.

        c                 S  s   g | ]}d t |iqS )r^   )r:   ).0subr   r   r   
<listcomp>6  s    z,MultiredditHelper.create.<locals>.<listcomp>)re   rc   rf   rg   rd   rh   ri   multireddit_basemodelr6   )r   r<   r   r   )	r   re   rc   rf   rg   rd   rh   ri   rq   r   r   r   r>     s   ,	zMultiredditHelper.create)r^   r:   r]   r_   r   r`   )re   r   rc   r:   rf   r   rg   r   rd   rl   rh   r:   ri   r:   r   r`   )r?   r@   rA   rB   r	   r   r>   r   r   r   r   r\      s&    r\   c                   @  s@   e Zd ZdZdddZedd	d
ddddddddddZdS )SubredditHelperz7Provide a set of functions to interact with Subreddits.rc   r:   r   praw.models.Subredditc                 C  s>   |  }|dkr| j S |dkr| jjddS t| j|dS )zqReturn a lazy instance of :class:`.Subreddit`.

        :param display_name: The name of the subreddit.

        randomrandnsfwT)r)   )rc   )lowerr   random_subredditr   )r   rc   
lower_namer   r   r   r   B  s   
zSubredditHelper.__call__r^   r/   	link_typesubreddit_typewikimodeanypublicNdisabled)ry   rz   r/   r{   r   other_settingsc             	   K  s,   t jd| j||||p||d| | |S )a  Create a new :class:`.Subreddit`.

        :param name: The name for the new subreddit.
        :param link_type: The types of submissions users can make. One of ``"any"``,
            ``"link"``, or ``"self"`` (default: ``"any"``).
        :param subreddit_type: One of ``"archived"``, ``"employees_only"``,
            ``"gold_only"``, ``"gold_restricted"``, ``"private"``, ``"public"``, or
            ``"restricted"`` (default: ``"public"``).
        :param title: The title of the subreddit. When ``None`` or ``""`` use the value
            of ``name``.
        :param wikimode: One of ``"anyone"``, ``"disabled"``, or ``"modonly"`` (default:
            ``"disabled"``).

        Any keyword parameters not provided, or set explicitly to ``None``, will take on
        a default value assigned by the Reddit server.

        .. seealso::

            :meth:`~.SubredditModeration.update` for documentation of other available
            settings.

        )r   ry   r^   rz   r/   r{   Nr   )r   _create_or_updater   )r   r^   ry   rz   r/   r{   r   r   r   r   r>   Q  s   !	zSubredditHelper.create)rc   r:   r   rs   )r^   r:   ry   r:   rz   r:   r/   r   r{   r:   r   r   r   rs   )r?   r@   rA   rB   r   r	   r>   r   r   r   r   rr   ?  s    
rr   )rB   
__future__r   jsonr   typingr   r   r   constr   utilr	   baser   reddit.draftr   reddit.liver   reddit.multir   r   praw.modelsprawr   rC   r\   rr   r   r   r   r   <module>   s     xjJ