o
    2g-                     @  s|   d Z ddlmZ ddl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 er4ddlZG dd deZdS )zProvide the draft class.    )annotations)TYPE_CHECKINGAny   )API_PATH)ClientException   )
RedditBase)	Subreddit)UserSubredditNc                      s   e Zd ZdZdZeddddddddddddd-ddZ	d.d/ fddZd0dd Z fd!d"Z	d#d$ Z
ddddddddd%d1d)d*Zddddddddddddd2d+d,Z  ZS )3Draftak  A class that represents a Reddit submission draft.

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

    ========================== ======================================================
    Attribute                  Description
    ========================== ======================================================
    ``link_flair_template_id`` The link flair's ID.
    ``link_flair_text``        The link flair's text content, or ``None`` if not
                               flaired.
    ``modified``               Time the submission draft was modified, represented in
                               `Unix Time`_.
    ``original_content``       Whether the submission draft will be set as original
                               content.
    ``selftext``               The submission draft's selftext. ``None`` if a link
                               submission draft.
    ``spoiler``                Whether the submission will be marked as a spoiler.
    ``subreddit``              Provides an instance of :class:`.Subreddit` or
                               :class:`.UserSubreddit` (if set).
    ``title``                  The title of the submission draft.
    ``url``                    The URL the submission draft links to.
    ========================== ======================================================

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

    idNflair_id
flair_textis_public_linknsfworiginal_contentselftextsend_repliesspoiler	subreddittitleurlr   
str | Noner   r   bool | Noner   r   r   r   r   r   8praw.models.Subreddit | praw.models.UserSubreddit | Noner   r   draft_kwargsr   returndict[str, Any]c                K  s^   |p|||||d urdnd|||||
d
}|	r(| |	j|	jdr#dndd | | |S )Nmarkdownlink)
bodyr   r   r   kindr   r   r   r   r   u_profiler   )r   target)updatefullnamedisplay_name
startswith)clsr   r   r   r   r   r   r   r   r   r   r   r   data r-   P/home/garg/my-data/venv/lib/python3.10/site-packages/praw/models/reddit/draft.py_prepare_data/   s*   


zDraft._prepare_dataredditpraw.Reddit_datac                   s   ||f ddkrd}t|d}|r|| _n#t|dkr:|d dkr+|d|d< n|d d	kr8|d|d
< d}t j|||d dS )z&Initialize a :class:`.Draft` instance.Nr   z0Exactly one of 'id' or '_data' must be provided.Fr#   r    r"   r   r!   r   T)r2   _fetched)count	TypeErrorr   lenpopsuper__init__)selfr0   r   r2   msgfetched	__class__r-   r.   r9   Z   s   zDraft.__init__strc                 C  sh   | j r)| jrd| jjnd}| jrd| jnd}| jj d| j| | dS | jj d| jdS )z?Return an object initialization representation of the instance.z subreddit= z title=z(id=))r3   r   r)   r   r>   __name__r   )r:   r   r   r-   r-   r.   __repr__l   s   zDraft.__repr__c                   sN   | j  D ]}|j| jkr| j|j t    d S qd| j }t|)Nz@The currently authenticated user not have a draft with an ID of )_redditdraftsr   __dict__r'   r8   _fetchr   )r:   draftr;   r=   r-   r.   rG   v   s   

zDraft._fetchc                 C  s   | j jtd d| jid dS )zDelete the :class:`.Draft`.

        Example usage:

        .. code-block:: python

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

        rH   draft_id)paramsN)rD   deleter   r   )r:   r-   r-   r.   rK      s   zDraft.delete)r   r   r   r   r   r   r   r   >str | praw.models.Subreddit | praw.models.UserSubreddit | Nonesubmit_kwargspraw.models.Submissionc                K  s   | j |	d< | js|sd}
t|
d|fd|fd|fd|fd|fd|fd	|ffD ]\}}|p2t| |d
}|d
ur;||	|< q't|trH| j|}nt|ttfrR|}n| j}|j	di |	S )a  Submit a 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 nsfw: Whether or not the submission should be marked NSFW (default:
            ``None``).
        :param selftext: The Markdown formatted content for a ``text`` submission. Use
            an empty string, ``""``, to make a title-only submission (default:
            ``None``).
        :param spoiler: Whether or not the submission should be marked as a spoiler
            (default: ``None``).
        :param subreddit: The subreddit to submit the draft to. This accepts a subreddit
            display name, :class:`.Subreddit` object, or :class:`.UserSubreddit` object.
        :param title: The title of the submission (default: ``None``).
        :param url: The URL for a ``link`` submission (default: ``None``).

        :returns: A :class:`.Submission` object for the newly created submission.

        .. note::

            Parameters set here will override their respective :class:`.Draft`
            attributes.

        Additional keyword arguments are passed to the :meth:`.Subreddit.submit` method.

        For example, to submit a draft as is:

        .. code-block:: python

            draft = reddit.drafts("5f87d55c-e4fb-11eb-8965-6aeb41b0880e")
            submission = draft.submit()

        For example, to submit a draft but use a different title than what is set:

        .. code-block:: python

            draft = reddit.drafts("5f87d55c-e4fb-11eb-8965-6aeb41b0880e")
            submission = draft.submit(title="New Title")

        .. seealso::

            - :meth:`~.Subreddit.submit` to submit url posts and selftexts
            - :meth:`~.Subreddit.submit_gallery`. to submit more than one image in the
              same post
            - :meth:`~.Subreddit.submit_image` to submit images
            - :meth:`~.Subreddit.submit_poll` to submit polls
            - :meth:`~.Subreddit.submit_video` to submit videos and videogifs

        rI   zN'subreddit' must be set on the Draft instance or passed as a keyword argument.r   r   r   r   r   r   r   Nr-   )
r   r   
ValueErrorgetattr
isinstancer?   rD   r
   r   submit)r:   r   r   r   r   r   r   r   r   rM   r;   key	attributevalue
_subredditr-   r-   r.   rR      s,   
B
	
zDraft.submitc                K  sv   t |	tr| j|	}	| jd|||||||||	|
|d|}| j|d< | jjtd |d}|  | j	
|j	 dS )a  Update the :class:`.Draft`.

        .. note::

            Only provided values will be updated.

        :param flair_id: The flair template to select.
        :param flair_text: If the template's ``flair_text_editable`` value is ``True``,
            this value will set a custom text. ``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.
        :param nsfw: Whether the draft should be marked NSFW.
        :param original_content: Whether the submission should be marked as original
            content.
        :param selftext: The Markdown formatted content for a text submission draft. Use
            ``None`` to make a title-only submission draft. ``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.
        :param spoiler: Whether the submission should be marked as a spoiler.
        :param subreddit: The subreddit to create the draft for. This accepts a
            subreddit display name, :class:`.Subreddit` object, or
            :class:`.UserSubreddit` object.
        :param title: The title of the draft.
        :param url: The URL for a ``link`` submission draft. ``url`` can not be provided
            if ``selftext`` is provided.

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

        For example, to update the title of a draft do:

        .. code-block:: python

            draft = reddit.drafts("5f87d55c-e4fb-11eb-8965-6aeb41b0880e")
            draft.update(title="New title")

        r   r   rH   )r,   Nr-   )rQ   r?   rD   r   r/   r   putr   rG   rF   r'   )r:   r   r   r   r   r   r   r   r   r   r   r   r   r,   
_new_draftr-   r-   r.   r'      s*   
9
zDraft.update)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )NN)r0   r1   r   r   r2   r   )r   r?   )r   r   r   r   r   r   r   r   r   r   r   rL   r   r   r   r   rM   r   r   rN   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rL   r   r   r   r   r   r   )rB   
__module____qualname____doc__	STR_FIELDclassmethodr/   r9   rC   rG   rK   rR   r'   __classcell__r-   r-   r=   r.   r      sT    +

]r   )r[   
__future__r   typingr   r   constr   
exceptionsr   baser	   r   r
   user_subredditr   praw.modelsprawr   r-   r-   r-   r.   <module>   s    