o
    Ujy                     @  s  d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZ d dl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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( d dl)m*Z*m+Z+ d dl,m-Z-m.Z. erd dl/m0Z0 G dd dZ1G dd dZ2G dd deZ3G dd dZ4eddG d d! d!Z5eG d"d# d#Z6d;d)d*Z7G d+d, d,Z8G d-d. d.Z9G d/d0 d0Z:G d1d2 d2Z;G d3d4 d4Z<eG d5d6 d6Z=G d7d8 d8Z>G d9d: d:Z?e? Z@dS )<    )annotationsN)defaultdict)Mapping)	dataclassreplace)Enumauto)TYPE_CHECKINGAnyClassVaroverload)Self)loggers)
Dispatcher)CallableObjectCallbackType)extract_flags_from_object)Router)SceneException)StateFilter)
FSMContext)StateMemoryStorageRecord)TelegramObjectUpdate)ClassAttrsResolverget_sorted_mro_attrs_resolver)NextMiddlewareTypec                   @  sh   e Zd Zd#d$d	d
Zd%ddZd&ddZd&ddZd'ddZd(ddZd(ddZ	d%ddZ
d)d d!Zd"S )*HistoryManagerscenes_history
   stater   destinystrsizeintc                 C  s*   || _ || _t|jt|j|dd| _d S )N)r#   )storagekey)_size_stater   r'   r   r(   _history_state)selfr"   r#   r%    r-   J/opt/telega-widget/.venv/lib/python3.10/site-packages/aiogram/fsm/scene.py__init__!   s   zHistoryManager.__init__
str | Nonedatadict[str, Any]returnNonec                   st   | j  I d H }|dg }|||d t|| jkr&|| j d  }tjd|| | j j	|dI d H  d S )Nhistoryr"   r1   z Push state=%s data=%s to historyr5   )
r+   get_data
setdefaultappendlenr)   r   scenedebugupdate_data)r,   r"   r1   history_datar5   r-   r-   r.   push)   s   zHistoryManager.pushMemoryStorageRecord | Nonec                   s   | j  I d H }|dg }|sd S | }|d }|d }|s+| j i I d H  n
| j j|dI d H  tjd|| t	||dS )Nr5   r"   r1   r7   z!Pop state=%s data=%s from historyr6   )
r+   r8   r9   popset_datar>   r   r<   r=   r   )r,   r?   r5   recordr"   r1   r-   r-   r.   rB   3   s   zHistoryManager.popc                   s8   | j  I d H }|dg }|sd S tdi |d S )Nr5   r-   )r+   r8   r9   r   r,   r?   r5   r-   r-   r.   getB   s   zHistoryManager.getlist[MemoryStorageRecord]c                   s,   | j  I d H }|dg }dd |D S )Nr5   c                 S  s   g | ]	}t d i |qS )r-   r   ).0itemr-   r-   r.   
<listcomp>L   s    z&HistoryManager.all.<locals>.<listcomp>)r+   r8   r9   rF   r-   r-   r.   allI   s   zHistoryManager.allc                   s$   t jd | ji I d H  d S )NzClear history)r   r<   r=   r+   rC   r,   r-   r-   r.   clearN   s   zHistoryManager.clearc                   s8   | j  I d H }| j  I d H }| ||I d H  d S N)r*   	get_stater8   r@   r,   r"   r1   r-   r-   r.   snapshotR   s   zHistoryManager.snapshotc                   s*   | j |I d H  | j |I d H  d S rO   )r*   	set_staterC   rQ   r-   r-   r.   
_set_stateW   s   zHistoryManager._set_statec                   sZ   |   I d H }|s| d i I d H  d S tjd|j|j | |j|jI d H  |jS )NzRollback to state=%s data=%s)rB   rT   r   r<   r=   r"   r1   )r,   previous_stater-   r-   r.   rollback[   s   zHistoryManager.rollbackN)r    r!   )r"   r   r#   r$   r%   r&   )r"   r0   r1   r2   r3   r4   )r3   rA   )r3   rH   r3   r4   )r3   r0   )__name__
__module____qualname__r/   r@   rB   rG   rL   rN   rR   rT   rV   r-   r-   r-   r.   r       s    







r   c                   @  sb   e Zd Z		d!d"ddZd#ddZd$ddZd%ddZd&ddZd'ddZd&ddZ	d&dd Z
dS )(ObserverDecoratorNnamer$   filterstuple[CallbackType, ...]actionSceneAction | NoneafterAfter | Noner3   r4   c                 C     || _ || _|| _|| _d S rO   )r\   r]   r_   ra   )r,   r\   r]   r_   ra   r-   r-   r.   r/   k      
zObserverDecorator.__init__targettype[Scene] | CallbackTypec                 C  s:   t |dd }|sg }||_|t| j|| j| jd d S )N__aiogram_handler__)r\   handlerr]   ra   )getattrrg   r:   HandlerContainerr\   r]   ra   )r,   re   handlersr-   r-   r.   _wrap_filterw   s   zObserverDecorator._wrap_filterr   c                 C  sL   | j d us	J dt|dd }|d u rtt}||_t||| j  | j< d S )NzScene action is not specified__aiogram_action__)r_   ri   r   dictrm   r   r\   )r,   re   r_   r-   r-   r.   _wrap_action   s   zObserverDecorator._wrap_actionc                 C  s<   t |r| jd u r| | |S | | |S d}t|)Nz"Only function or method is allowed)inspect
isfunctionr_   rl   ro   	TypeError)r,   re   msgr-   r-   r.   __call__   s   



zObserverDecorator.__call__ActionContainerc                 C     t | j| jtjS rO   )ru   r\   r]   SceneActionleaverM   r-   r-   r.   rx         zObserverDecorator.leavetype[Scene]c                 C  s   t | j| jtj|S rO   )ru   r\   r]   rw   enter)r,   re   r-   r-   r.   r{      s   zObserverDecorator.enterc                 C  rv   rO   )ru   r\   r]   rw   exitrM   r-   r-   r.   r|      ry   zObserverDecorator.exitc                 C  rv   rO   )ru   r\   r]   rw   backrM   r-   r-   r.   r}      ry   zObserverDecorator.back)NN)
r\   r$   r]   r^   r_   r`   ra   rb   r3   r4   )re   rf   r3   r4   )re   r   r3   r4   )re   r   r3   r   )r3   ru   )re   rz   r3   ru   )rX   rY   rZ   r/   rl   ro   rt   rx   r{   r|   r}   r-   r-   r-   r.   r[   j   s    


	


r[   c                   @  s$   e Zd Ze Ze Ze Ze ZdS )rw   N)rX   rY   rZ   r   r{   rx   r|   r}   r-   r-   r-   r.   rw      s
    
rw   c                   @  s$   e Zd Z	ddddZdddZdS )ru   Nr\   r$   r]   r^   r_   rw   re    type[Scene] | State | str | Noner3   r4   c                 C  rc   rO   )r\   r]   r_   re   )r,   r\   r]   r_   re   r-   r-   r.   r/      rd   zActionContainer.__init__wizardSceneWizardc                   s   | j tjkr| jd ur|| jI d H  d S | j tjkr&| I d H  d S | j tjkr5| I d H  d S | j tjkrD| I d H  d S d S rO   )r_   rw   r{   re   gotorx   r|   r}   r,   r   r-   r-   r.   execute   s   zActionContainer.executerO   )
r\   r$   r]   r^   r_   rw   re   r~   r3   r4   r   r   r3   r4   )rX   rY   rZ   r/   r   r-   r-   r-   r.   ru      s    ru   T)slotsc                   @  s2   e Zd ZU ded< ded< ded< dZded	< dS )
rj   r$   r\   r   rh   r^   r]   Nrb   ra   )rX   rY   rZ   __annotations__ra   r-   r-   r-   r.   rj      s
   
 rj   c                   @  sb   e Zd ZU ded< 	 ded< 	 ded< 	 dZded	< 	 dZded
< 	 dZded< 	 eZded< dS )SceneConfigr0   r"   zlist[HandlerContainer]rk   z,dict[SceneAction, dict[str, CallableObject]]actionsNzbool | Nonereset_data_on_enterreset_history_on_entercallback_query_without_stater   attrs_resolver)	rX   rY   rZ   r   r   r   r   r   r   r-   r-   r-   r.   r      s   
 r   argsr
   kwargsr3   r4   c                    s   d S rO   r-   )r   r   r-   r-   r.   _empty_handler   s   r   c                   @  s8   e Zd Z	ddd
dZdddZdddZdddZdS )SceneHandlerWrapperNr<   rz   rh   r   ra   rb   r3   r4   c                 C  s   || _ t|| _|| _d S rO   )r<   r   rh   ra   )r,   r<   rh   ra   r-   r-   r.   r/      s   

zSceneHandlerWrapper.__init__eventr   r   r
   c              
     s   z
|d }|d }W n t y' } z|jd }d|d}t|d d }~ww |d }i |j||_| jt| jj|||j||dd}	| jj	|	|fi |I d H }
| j
rjtd	d
| j
j| j
j}||	jI d H  |
S )Nr"   scenesr   zScene context key z@ is not available. Ensure FSM is enabled and pipeline is intact.event_updatescene_configmanagerr"   update_typer   r1   r   ra   r-   )KeyErrorr   r   r1   r<   r   __scene_config__
event_typerh   callra   ru   r_   r   r   )r,   r   r   r"   r   errormissing_keyrs   r   r<   resultaction_containerr-   r-   r.   rt      sB   


zSceneHandlerWrapper.__call__r   c                 C  s   | S rO   r-   rM   r-   r-   r.   	__await__  s   zSceneHandlerWrapper.__await__r$   c                 C  s8   d| j  d| jj }| jr|d| j 7 }|d7 }|S )NzSceneHandlerWrapper(z, z, after=))r<   rh   callbackra   )r,   r   r-   r-   r.   __str__!  s
   zSceneHandlerWrapper.__str__rO   )r<   rz   rh   r   ra   rb   r3   r4   )r   r   r   r
   r3   r
   )r3   r   )r3   r$   )rX   rY   rZ   r/   rt   r   r   r-   r-   r-   r.   r      s    


(r   c                      sd   e Zd ZU dZded< 	 ddd	Zd fddZedddZeddddZ	ed ddZ
  ZS )!Scenea  
    Represents a scene in a conversation flow.

    A scene is a specific state in a conversation where certain actions can take place.

    Each scene has a set of filters that determine when it should be triggered,
    and a set of handlers that define the actions to be executed when the scene is active.

    .. note::
        This class is not meant to be used directly. Instead, it should be subclassed
        to define custom scenes.
    zClassVar[SceneConfig]r   r   r   r3   r4   c                 C  s   || _ | | j _d S rO   )r   r<   r   r-   r-   r.   r/   :  s   zScene.__init__r   r
   c              	     sf  | dd }| dd }| dd }| dd }| dd }t jdi | g }tt}| jD ]-}	t|	ts8q0t|	dd }
|
sAq0|d u rH|
j	}|d u rO|
j
}|d u rV|
j}|d u r]|
j}q0|d u rdt}|| D ]:\}}t|dd  }ry|| t|tr|t|jt|j|jd t|d	r|j D ]\}}|| | qqht||t|||||d
| _d S )Nr"   r   r   r   r   r   rg   ra   rm   )r"   rk   r   r   r   r   r   r-   )rB   super__init_subclass__r   rn   	__bases__
issubclassr   ri   r   r   r   r   r   extend
isinstancer[   r:   rj   r\   r   r]   ra   hasattrrm   itemsupdater   r   )clsr   
state_namer   r   r   r   rk   r   baseparent_scene_config_namevaluescene_handlersr_   action_handlers	__class__r-   r.   r   A  sd   




zScene.__init_subclass__routerr   c                 C  s   | j }t }|jD ]#}|j|j jt| |j|jdg|j	R dt
|ji ||j q	|D ]}|jr9|dkr9q/|j| t|j q/dS )z^
        Adds the scene to the given router.

        :param router:
        :return:
        r   flagscallback_queryN)r   setrk   	observersr\   registerr   rh   ra   r]   r   addr   filterr   r"   )r   r   r   used_observersrh   observer_namer-   r-   r.   add_to_router{  s(   
	zScene.add_to_routerNr\   r0   c                 C  s>   |du rd| j  d| j d| jj}t|d}| | |S )zM
        Returns the scene as a router.

        :return: new router
        NzScene '.z' for state r\   )rY   rZ   r   r"   r   r   )r   r\   r   r-   r-   r.   	as_router  s   

zScene.as_routerhandler_kwargsr   c                   s   d fd	d
}|S )z
        Create an entry point handler for the scene, can be used to simplify the handler
        that starts the scene.

        >>> router.message.register(MyScene.as_handler(), Command("start"))
        r   r   r   ScenesManagermiddleware_kwargsr
   r3   r4   c                   s&   |j  fi i |I d H  d S rO   )r{   )r   r   r   r   r   r-   r.   enter_to_scene_handler  s   $z0Scene.as_handler.<locals>.enter_to_scene_handlerN)r   r   r   r   r   r
   r3   r4   r-   )r   r   r   r-   r   r.   
as_handler  s   	zScene.as_handlerr   r   r
   r3   r4   r   r   r3   r4   rO   )r\   r0   r3   r   )r   r
   r3   r   )rX   rY   rZ   __doc__r   r/   r   classmethodr   r   r   __classcell__r-   r-   r   r.   r   )  s   
 
:r   c                   @  s   e Zd ZdZd;ddZd<ddZd=d>ddZd<ddZd<ddZd<dd Z	d?d#d$Z
d@d'd(ZdAd*d+ZdBd,d-ZedCd0d1ZedDd3d1ZdEdFd5d1Z	4dEdGd7d8ZdHd9d:Zd4S )Ir   as  
    A class that represents a wizard for managing scenes in a Telegram bot.

    Instance of this class is passed to each scene as a parameter.
    So, you can use it to transition between scenes, get and set data, etc.

    .. note::

        This class is not meant to be used directly. Instead, it should be used
        as a parameter in the scene constructor.

    r   r   r   r   r"   r   r   r$   r   r   r1   r2   c                 C  s.   || _ || _|| _|| _|| _|| _d| _dS )a  
        A class that represents a wizard for managing scenes in a Telegram bot.

        :param scene_config: The configuration of the scene.
        :param manager: The scene manager.
        :param state: The FSMContext object for storing the state of the scene.
        :param update_type: The type of the update event.
        :param event: The TelegramObject represents the event.
        :param data: Additional data for the scene.
        N)r   r   r"   r   r   r1   r<   )r,   r   r   r"   r   r   r1   r-   r-   r.   r/     s   
zSceneWizard.__init__r   r
   r3   r4   c                   s|   t jd| jj | jjr| ji I dH  | jjr$| jj	
 I dH  | j| jjI dH  | jtjfi |I dH  dS )a  
        Enter method is used to transition into a scene in the SceneWizard class.
        It sets the state, clears data and history if specified,
        and triggers entering event of the scene.

        :param kwargs: Additional keyword arguments.
        :return: None
        zEntering scene %rN)r   r<   r=   r   r"   r   rC   r   r   r5   rN   rS   
_on_actionrw   r{   r,   r   r-   r-   r.   r{     s   	zSceneWizard.enterT_with_historyboolc                   sH   t jd| jj |r| jj I dH  | jt	j
fi |I dH  dS )a"  
        Leaves the current scene.
        This method is used to exit a scene and transition to the next scene.

        :param _with_history: Whether to include history in the snapshot. Defaults to True.
        :param kwargs: Additional keyword arguments.
        :return: None

        zLeaving scene %rN)r   r<   r=   r   r"   r   r5   rR   r   rw   rx   )r,   r   r   r-   r-   r.   rx     s
   
zSceneWizard.leavec                   s`   t jd| jj | jj I dH  | jt	j
fi |I dH  | jjdddi|I dH  dS )z
        Exit the current scene and enter the default scene/state.

        :param kwargs: Additional keyword arguments.
        :return: None
        zExiting scene %rN_check_activeFrO   )r   r<   r=   r   r"   r   r5   rN   r   rw   r|   r{   r   r-   r-   r.   r|     s
    zSceneWizard.exitc                   sb   t jd| jj | jdddi|I dH  | jj I dH }| jj	|fddi|I dH  dS )z
        This method is used to go back to the previous scene.

        :param kwargs: Keyword arguments that can be passed to the method.
        :return: None
        z$Back to previous scene from scene %sr   FNr   r-   )
r   r<   r=   r   r"   rx   r   r5   rV   r{   )r,   r   	new_scener-   r-   r.   r}     s
   "zSceneWizard.backc                   s6   | j jdusJ d| j| j jfi |I dH  dS )z
        This method allows to re-enter the current scene.

        :param kwargs: Additional keyword arguments to pass to the scene.
        :return: None
        NzScene state is not specified)r   r"   r   r   r-   r-   r.   retake  s    zSceneWizard.retaker<   type[Scene] | State | strc                   s:   | j di |I dH  | jj|fddi|I dH  dS )a  
        The `goto` method transitions to a new scene.
        It first calls the `leave` method to perform any necessary cleanup
        in the current scene, then calls the `enter` event to enter the specified scene.

        :param scene: The scene to transition to. Can be either a `Scene` instance
            `State` instance or a string representing the scene.
        :param kwargs: Additional keyword arguments to pass to the `enter`
            method of the scene manager.
        :return: None
        Nr   Fr-   )rx   r   r{   )r,   r<   r   r-   r-   r.   r   &  s   "zSceneWizard.gotor_   rw   c                   s   | j s
d}t|tj d|j| jj | jj|i }|s,tj d|j| jj dS | j	}||vrAtj d|j|| jj dS || j
| j | jfi i | j|I d H  dS )NzScene is not initializedzCall action %r in scene %rzAction %r not found in scene %rFz,Action %r for event %r not found in scene %rT)r<   r   r   r=   r\   r   r"   r   rG   r   r   r   r1   )r,   r_   r   rs   action_configr   r-   r-   r.   r   5  s0   ,zSceneWizard._on_actionMapping[str, Any]c                   s   | j j|dI dH  dS )z
        Sets custom data in the current state.

        :param data: A mapping containing the custom data to be set in the current state.
        :return: None
        r1   N)r"   rC   )r,   r1   r-   r-   r.   rC   Q  s   zSceneWizard.set_datac                   s   | j  I dH S )z
        This method returns the data stored in the current state.

        :return: A dictionary containing the data stored in the scene state.
        N)r"   r8   rM   r-   r-   r.   r8   Z  s   zSceneWizard.get_datar(   
Any | Nonec                      dS )z
        This method returns the value from key in the data of the current state.

        :param key: The keyname of the item you want to return the value from.

        :return: A dictionary containing the data stored in the scene state.
        Nr-   )r,   r(   r-   r-   r.   	get_valueb      zSceneWizard.get_valuedefaultc                   r   )aC  
        This method returns the value from key in the data of the current state.

        :param key: The keyname of the item you want to return the value from.
        :param default: Default value to return, if ``key`` was not found.

        :return: A dictionary containing the data stored in the scene state.
        Nr-   r,   r(   r   r-   r-   r.   r   l  r   Nc                   s   | j ||I d H S rO   )r"   r   r   r-   r-   r.   r   w  s   Mapping[str, Any] | Nonec                   s$   |r| | | jj|dI dH S )z
        This method updates the data stored in the current state

        :param data: Optional mapping of data to update.
        :param kwargs: Additional key-value pairs of data to update.
        :return: Dictionary of updated data
        r   N)r   r"   r>   )r,   r1   r   r-   r-   r.   r>   z  s   
zSceneWizard.update_datac                   s   |  i I dH  dS )z9
        Clears the data.

        :return: None
        N)rC   rM   r-   r-   r.   
clear_data  s   zSceneWizard.clear_data)r   r   r   r   r"   r   r   r$   r   r   r1   r2   r   T)r   r   r   r
   r3   r4   )r<   r   r   r
   r3   r4   )r_   rw   r   r
   r3   r   )r1   r   r3   r4   )r3   r2   )r(   r$   r3   r   )r(   r$   r   r
   r3   r
   rO   )r(   r$   r   r   r3   r   )r1   r   r   r
   r3   r2   rW   )rX   rY   rZ   r   r/   r{   rx   r|   r}   r   r   r   rC   r8   r   r   r>   r   r-   r-   r-   r.   r     s(    









		
r   c                   @  sF   e Zd ZdZd"ddZd#ddZd$ddZ	d%d&ddZd'dd Zd!S )(r   z
    The ScenesManager class is responsible for managing scenes in an application.
    It provides methods for entering and exiting scenes, as well as retrieving the active scene.
    registrySceneRegistryr   r$   r   r   r"   r   r1   r2   r3   r4   c                 C  s.   || _ || _|| _|| _|| _t| j| _d S rO   )r   r   r   r"   r1   r   r5   )r,   r   r   r   r"   r1   r-   r-   r.   r/     s   zScenesManager.__init__
scene_typer~   r   c              	     s2   | j |}|t|j| | j| j| j| jddS )Nr   r   )r   rG   r   r   r"   r   r   r1   )r,   r   r-   r-   r.   
_get_scene  s   zScenesManager._get_sceneScene | Nonec                   s:   | j  I d H }z	| |I d H W S  ty   Y d S w rO   )r"   rP   r   r   )r,   r"   r-   r-   r.   _get_active_scene  s   zScenesManager._get_active_sceneTr   r   r   r
   c                   s   |ri | j || _ |r$|  I dH }|dur$|jjdi |I dH  z
| |I dH }W n tyF   |dur: | jdI dH  Y dS w |jjdi |I dH  dS )a  
        Enters the specified scene.

        :param scene_type: Optional Type[Scene], State or str representing the scene type to enter.
        :param _check_active: Optional bool indicating whether to check if
            there is an active scene to exit before entering the new scene. Defaults to True.
        :param kwargs: Additional keyword arguments to pass to the scene's wizard.enter() method.
        :return: None
        Nr-   )	r1   r   r   r|   r   r   r"   rS   r{   )r,   r   r   r   active_scener<   r-   r-   r.   r{     s   zScenesManager.enterc                   s4   |   I dH }|sdS |jjdi |I dH  dS )z
        Close method is used to exit the currently active scene in the ScenesManager.

        :param kwargs: Additional keyword arguments passed to the scene's exit method.
        :return: None
        Nr-   )r   r   r|   )r,   r   r<   r-   r-   r.   close  s
   zScenesManager.closeN)r   r   r   r$   r   r   r"   r   r1   r2   r3   r4   )r   r~   r3   r   )r3   r   r   )r   r~   r   r   r   r
   r3   r4   r   )	rX   rY   rZ   r   r/   r   r   r{   r   r-   r-   r-   r.   r     s    



 r   c                   @  s^   e Zd ZdZd%d&d	d
Zd'ddZd(ddZd(ddZddd)ddZd*dd Z	d+d#d$Z
dS ),r   zJ
    A class that represents a registry for scenes in a Telegram bot.
    Tr   r   register_on_addr   r3   r4   c                 C  s    || _ || _i | _| | dS )z
        Initialize a new instance of the SceneRegistry class.

        :param router: The router instance used for scene registration.
        :param register_on_add: Whether to register the scenes to the router when they are added.
        N)r   r   _scenes_setup_middleware)r,   r   r   r-   r-   r.   r/     s   zSceneRegistry.__init__c                 C  sH   t |tr|j| j d S |j D ]}|jdv rq|| j qd S )N>   r   r   )	r   r   r   outer_middleware_update_middlewarer   values
event_name_middleware)r,   r   observerr-   r-   r.   r     s   

zSceneRegistry._setup_middlewarerh   "NextMiddlewareType[TelegramObject]r   r   r1   r2   r
   c                   s`   t |ts
J d|d}|d u r|||I d H S t| |j|j||d|d< |||I d H S )Nz Event must be an Update instancer"   r   r   r   r"   r1   r   )r   r   rG   r   r   r   )r,   rh   r   r1   r"   r-   r-   r.   r     s   

z SceneRegistry._update_middlewarec                   sT   | d}|d u r|||I d H S |d }t| |j|||d|d< |||I d H S )Nr"   r   r   r   )rG   r   r   )r,   rh   r   r1   r"   r   r-   r-   r.   r     s   

zSceneRegistry._middlewareN)r   r   rz   Router | Nonec                G  s|   |sd}t ||D ]1}|jj| jv rd|jjd}t||| j|jj< |r0||  q
| jr;| j|  q
dS )a  
        This method adds the specified scenes to the registry
        and optionally registers it to the router.

        If a scene with the same state already exists in the registry, a SceneException is raised.

        .. warning::

            If the router is not specified, the scenes will not be registered to the router.
            You will need to include the scenes manually to the router or use the register method.

        :param scenes: A variable length parameter that accepts one or more types of scenes.
            These scenes are instances of the Scene class.
        :param router: An optional parameter that specifies the router
            to which the scenes should be added.
        :return: None
        z$At least one scene must be specifiedzScene with state z already existsN)	
ValueErrorr   r"   r   r   include_routerr   r   r   )r,   r   r   rs   r<   r-   r-   r.   r   0  s   zSceneRegistry.addc                 G  s   | j |d| ji dS )z
        Registers one or more scenes to the SceneRegistry.

        :param scenes: One or more scene classes to register.
        :return: None
        r   N)r   r   )r,   r   r-   r-   r.   r   R  s   zSceneRegistry.registerr<   r~   c                 C  s|   t |rt|tr|jj}t|tr|j}|dur%t|ts%d}t	|z| j
| W S  ty=   d|d}t	|dw )ae  
        This method returns the registered Scene object for the specified scene.
        The scene parameter can be either a Scene object, State object or a string representing
        the name of the scene. If a Scene object is provided, the state attribute
        of the SceneConfig object associated with the Scene object will be used as the scene name.
        If a State object is provided, the state attribute of the State object will be used as the
        scene name. If None or an invalid type is provided, a SceneException will be raised.

        If the specified scene is not registered in the SceneRegistry object,
        a SceneException will be raised.

        :param scene: A Scene object, State object or a string representing the name of the scene.
        :return: The registered Scene object corresponding to the given scene parameter.

        Nz4Scene must be a subclass of Scene, State or a stringzScene z is not registered)rp   isclassr   r   r   r"   r   r   r$   r   r   r   )r,   r<   rs   r-   r-   r.   rG   [  s   

zSceneRegistry.getr   )r   r   r   r   r3   r4   r   )rh   r   r   r   r1   r2   r3   r
   )r   rz   r   r   r3   r4   )r   rz   r3   r4   )r<   r~   r3   rz   )rX   rY   rZ   r   r/   r   r   r   r   r   rG   r-   r-   r-   r.   r     s    



"	r   c                   @  sL   e Zd ZU ded< dZded< edddZedd	d
ZedddZdS )Afterrw   r_   Nr~   r<   r3   c                 C     | t jdS Nr_   )rw   r|   r   r-   r-   r.   r|        z
After.exitc                 C  r   r   )rw   r}   r  r-   r-   r.   r}     r  z
After.backc                 C  s   | t j|dS )N)r_   r<   )rw   r{   )r   r<   r-   r-   r.   r     s   z
After.goto)r3   r   )r<   r~   r3   r   )	rX   rY   rZ   r   r<   r   r|   r}   r   r-   r-   r-   r.   r   z  s   
 r   c                   @  sN   e Zd ZdddZdddddZdddZdddZdddZdddZdS )ObserverMarkerr\   r$   r3   r4   c                 C  s
   || _ d S rO   r   )r,   r\   r-   r-   r.   r/     s   
zObserverMarker.__init__Nr   r]   r   ra   rb   r[   c                G  s   t | j||dS )Nr   )r[   r\   )r,   ra   r]   r-   r-   r.   rt     s
   zObserverMarker.__call__c                 G  s   t | j|tjdS r   )r[   r\   rw   r{   )r,   r]   r-   r-   r.   r{     ry   zObserverMarker.enterc                 C     t | jdtjdS Nr-   r  )r[   r\   rw   rx   rM   r-   r-   r.   rx     ry   zObserverMarker.leavec                 C  r  r  )r[   r\   rw   r|   rM   r-   r-   r.   r|     ry   zObserverMarker.exitc                 C  r  r  )r[   r\   rw   r}   rM   r-   r-   r.   r}     ry   zObserverMarker.back)r\   r$   r3   r4   )r]   r   ra   rb   r3   r[   )r]   r   r3   r[   )r3   r[   )	rX   rY   rZ   r/   rt   r{   rx   r|   r}   r-   r-   r-   r.   r    s    



r  c                   @  s   e Zd ZdZedZedZedZedZedZ	edZ
edZed	Zed
ZedZedZedZedZedZdS )OnMarkera}  
    The `OnMarker` class is used as a marker class to define different
    types of events in the Scenes.

    Attributes:

    - :code:`message`: Event marker for handling `Message` events.
    - :code:`edited_message`: Event marker for handling edited `Message` events.
    - :code:`channel_post`: Event marker for handling channel `Post` events.
    - :code:`edited_channel_post`: Event marker for handling edited channel `Post` events.
    - :code:`inline_query`: Event marker for handling `InlineQuery` events.
    - :code:`chosen_inline_result`: Event marker for handling chosen `InlineResult` events.
    - :code:`callback_query`: Event marker for handling `CallbackQuery` events.
    - :code:`shipping_query`: Event marker for handling `ShippingQuery` events.
    - :code:`pre_checkout_query`: Event marker for handling `PreCheckoutQuery` events.
    - :code:`poll`: Event marker for handling `Poll` events.
    - :code:`poll_answer`: Event marker for handling `PollAnswer` events.
    - :code:`my_chat_member`: Event marker for handling my chat `Member` events.
    - :code:`chat_member`: Event marker for handling chat `Member` events.
    - :code:`chat_join_request`: Event marker for handling chat `JoinRequest` events.
    - :code:`error`: Event marker for handling `Error` events.

    .. note::

        This is a marker class and does not contain any methods or implementation logic.
    messageedited_messagechannel_postedited_channel_postinline_querychosen_inline_resultr   shipping_querypre_checkout_querypollpoll_answermy_chat_memberchat_memberchat_join_requestN)rX   rY   rZ   r   r  r  r	  r
  r  r  r  r   r  r  r  r  r  r  r  r-   r-   r-   r.   r    s     r  )r   r
   r   r
   r3   r4   )A
__future__r   rp   collectionsr   collections.abcr   dataclassesr   r   enumr   r   typingr	   r
   r   r   typing_extensionsr   aiogramr   aiogram.dispatcher.dispatcherr    aiogram.dispatcher.event.handlerr   r   aiogram.dispatcher.flagsr   aiogram.dispatcher.routerr   aiogram.exceptionsr   aiogram.filtersr   aiogram.fsm.contextr   aiogram.fsm.stater   aiogram.fsm.storage.memoryr   aiogram.typesr   r   "aiogram.utils.class_attrs_resolverr   r   aiogram.dispatcher.event.basesr   r   r[   rw   ru   rj   r   r   r   r   r   r   r   r   r  r  onr-   r-   r-   r.   <module>   sX    J=
>  ZW 
,