o
    2g!                     @  s   d 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mZ d	d
lmZ er8ddlZG dd deZG dd dZdS )z!Provide the Removal Reason class.    )annotations)TYPE_CHECKINGAnyIterator)warn   )API_PATH)ClientException)_deprecate_argscachedproperty   )
RedditBaseNc                      s   e Zd ZdZdZed$ddZd%ddZd&ddZ			d'd( fddZ	 fddZ
dd Zedd ddd!d)d"d#Z  ZS )*RemovalReasona  An individual Removal Reason object.

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

    =========== ==================================
    Attribute   Description
    =========== ==================================
    ``id``      The ID of the removal reason.
    ``message`` The message of the removal reason.
    ``title``   The title of the removal reason.
    =========== ==================================

    idid_value
str | Nonereason_id_valuereturnc                 C  s   |durt dtdd |S | S )a  Reason ID param is deprecated. Warns if it's used.

        :param id_value: Returns the actual value of parameter ``id`` is parameter
            ``reason_id`` is not used.
        :param reason_id_value: The value passed as parameter ``reason_id``.

        NzParameter 'reason_id' is deprecated. Either use positional arguments (e.g., reason_id="x" -> "x") or change the parameter name to 'id' (e.g., reason_id="x" -> id="x"). This parameter will be removed in PRAW 8.r   )category
stacklevel)r   DeprecationWarningr   r    r   Z/home/garg/my-data/venv/lib/python3.10/site-packages/praw/models/reddit/removal_reasons.py_warn_reason_id"   s   zRemovalReason._warn_reason_idotherstr | RemovalReasonboolc                 C  s2   t |tr|t| kS t || jot| t|kS )z5Return whether the other instance equals the current.)
isinstancestr	__class__)selfr   r   r   r   __eq__9   s   
zRemovalReason.__eq__intc                 C  s   t | jjt t| A S )z(Return the hash of the current instance.)hashr    __name__r   r!   r   r   r   __hash__?   s   zRemovalReason.__hash__Nredditpraw.Reddit	subredditpraw.models.Subreddit	reason_id_datadict[str, Any] | Nonec                   sP   | j ||d}||fddkrd}t||r|| _|| _t j||d dS )av  Initialize a :class:`.RemovalReason` instance.

        :param reddit: An instance of :class:`.Reddit`.
        :param subreddit: An instance of :class:`.Subreddit`.
        :param id: The ID of the removal reason.
        :param reason_id: The original name of the ``id`` parameter. Used for backwards
            compatibility. This parameter should not be used.

        r   Nr   z%Either id or _data needs to be given.r-   )r   count
ValueErrorr   r*   super__init__)r!   r(   r*   r   r,   r-   msgr    r   r   r3   C   s   zRemovalReason.__init__c                   sV   | j jjD ]}|j| jkr| j|j t    d S qd| j  d| j }t|)Nz
Subreddit z" does not have the removal reason )	r*   modremoval_reasonsr   __dict__updater2   _fetchr	   )r!   removal_reasonr4   r5   r   r   r:   ^   s   
zRemovalReason._fetchc                 C  s&   t d j| j| jd}| j| dS )zDelete a removal reason from this subreddit.

        To delete ``"141vv5c16py7d"`` from r/test try:

        .. code-block:: python

            reddit.subreddit("test").mod.removal_reasons["141vv5c16py7d"].delete()

        r;   r*   r   N)r   formatr*   r   _redditdelete)r!   urlr   r   r   r?   g   s   
zRemovalReason.deletemessagetitlerA   rB   c                  sF   t d j j jd} fdd||d D } jj||d dS )a  Update the removal reason from this subreddit.

        .. note::

            Existing values will be used for any unspecified arguments.

        :param message: The removal reason's new message.
        :param title: The removal reason's new title.

        To update ``"141vv5c16py7d"`` from r/test try:

        .. code-block:: python

            reddit.subreddit("test").mod.removal_reasons["141vv5c16py7d"].update(
                title="New title", message="New message"
            )

        r;   r<   c                   s(   i | ]\}}||d u rt  |n|qS )N)getattr).0namevaluer&   r   r   
<dictcomp>   s    z(RemovalReason.update.<locals>.<dictcomp>rC   dataN)r   r=   r*   r   itemsr>   put)r!   rA   rB   r@   rJ   r   r&   r   r9   t   s
   
zRemovalReason.update)r   r   r   r   r   r   )r   r   r   r   )r   r#   )NNN)
r(   r)   r*   r+   r   r   r,   r   r-   r.   )rA   r   rB   r   )r%   
__module____qualname____doc__	STR_FIELDstaticmethodr   r"   r'   r3   r:   r?   r
   r9   __classcell__r   r   r5   r   r      s    

	r   c                   @  sP   e Zd ZdZedddZdd	d
ZdddZdddZe	dddddZ
dS )SubredditRemovalReasonszFProvide a set of functions to a :class:`.Subreddit`'s removal reasons.r   list[RemovalReason]c                   s2   j td jjd  fdd d D S )zrGet a list of Removal Reason objects.

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

        removal_reasons_listr*   c                   s&   g | ]}t jj d  | dqS )rJ   r/   )r   r>   r*   )rE   r,   responser!   r   r   
<listcomp>   s    z@SubredditRemovalReasons._removal_reason_list.<locals>.<listcomp>order)r>   getr   r=   r*   r&   r   rW   r   _removal_reason_list   s   z,SubredditRemovalReasons._removal_reason_listr,   str | int | slicer   c                 C  s$   t |ts
| j| S t| j| j|S )ac  Return the Removal Reason with the ID/number/slice ``reason_id``.

        :param reason_id: The ID or index of the removal reason

        .. note::

            Removal reasons fetched using a specific rule name are lazily loaded, so you
            might have to access an attribute to get all the expected attributes.

        This method is to be used to fetch a specific removal reason, like so:

        .. code-block:: python

            reason_id = "141vv5c16py7d"
            reason = reddit.subreddit("test").mod.removal_reasons[reason_id]
            print(reason)

        You can also use indices to get a numbered removal reason. Since Python uses
        0-indexing, the first removal reason is index 0, and so on.

        .. note::

            Both negative indices and slices can be used to interact with the removal
            reasons.

        :raises: :py:class:`IndexError` if a removal reason of a specific number does
            not exist.

        For example, to get the second removal reason of r/test:

        .. code-block:: python

            reason = reddit.subreddit("test").mod.removal_reasons[1]

        To get the last three removal reasons in a subreddit:

        .. code-block:: python

            reasons = reddit.subreddit("test").mod.removal_reasons[-3:]
            for reason in reasons:
                print(reason)

        )r   r   r\   r   r>   r*   )r!   r,   r   r   r   __getitem__   s   
,
z#SubredditRemovalReasons.__getitem__r*   r+   c                 C  s   || _ |j| _dS )zInitialize a :class:`.SubredditRemovalReasons` instance.

        :param subreddit: The subreddit whose removal reasons to work with.

        N)r*   r>   )r!   r*   r   r   r   r3      s   z SubredditRemovalReasons.__init__Iterator[RemovalReason]c                 C  s
   t | jS )a"  Return a list of Removal Reasons for the subreddit.

        This method is used to discover all removal reasons for a subreddit:

        .. code-block:: python

            for removal_reason in reddit.subreddit("test").mod.removal_reasons:
                print(removal_reason)

        )iterr\   r&   r   r   r   __iter__   s   
z SubredditRemovalReasons.__iter__rA   rB   r   c                C  s<   ||d}t d j| jd}| jj||d}t| j| j|S )a  Add a removal reason to this subreddit.

        :param message: The message associated with the removal reason.
        :param title: The title of the removal reason.

        :returns: The :class:`.RemovalReason` added.

        The message will be prepended with ``Hi u/username,`` automatically.

        To add ``"Test"`` to r/test try:

        .. code-block:: python

            reddit.subreddit("test").mod.removal_reasons.add(title="Test", message="Foobar")

        rC   rU   rV   rI   )r   r=   r*   r>   postr   )r!   rA   rB   rJ   r@   r,   r   r   r   add   s   
zSubredditRemovalReasons.addN)r   rT   )r,   r]   r   r   )r*   r+   )r   r_   )rA   r   rB   r   r   r   )r%   rM   rN   rO   r   r\   r^   r3   ra   r
   rc   r   r   r   r   rS      s    

0
	rS   )rO   
__future__r   typingr   r   r   warningsr   constr   
exceptionsr	   utilr
   r   baser   prawr   rS   r   r   r   r   <module>   s    