
    ,hb                    v   d dl mZ d dl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mZmZ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 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/m0Z0m1Z1 d dl2m3Z3m4Z4  G d d      Z5 G d d      Z6 G d de	      Z7 G d d      Z8 G d d      Z9 e        G d d              Z:d2d!Z; G d" d#      Z< G d$ d%      Z= G d& d'      Z> G d( d)      Z? G d* d+      Z@e G d, d-             ZA G d. d/      ZB G d0 d1      ZC eC       ZDy)3    )annotationsN)defaultdict)	dataclassreplace)Enumauto)
AnyClassVarDictListMappingOptionalTupleTypeUnionoverload)Self)loggers)
Dispatcher)NextMiddlewareType)CallableObjectCallbackType)extract_flags_from_object)Router)SceneException)StateFilter)
FSMContext)State)MemoryStorageRecord)TelegramObjectUpdate)ClassAttrsResolverget_sorted_mro_attrs_resolverc                  V    e Zd ZdddZddZddZddZddZddZddZ	ddZ
dd	Zy
)HistoryManagerc                    || _         || _        t        |j                  t	        |j
                  |            | _        y )N)destiny)storagekey)_size_stater   r(   r   r)   _history_state)selfstater'   sizes       D/var/www/html/venv/lib/python3.12/site-packages/aiogram/fsm/scene.py__init__zHistoryManager.__init__)   s1    
(MMwuyy''J
    c                ~  K   | j                   j                          d {   }|j                  dg       }|j                  ||d       t	        |      | j
                  kD  r|| j
                   d  }t        j                  j                  d||       | j                   j                  |       d {    y 7 7 w)Nhistoryr.   dataz Push state=%s data=%s to historyr4   )
r,   get_data
setdefaultappendlenr*   r   scenedebugupdate_data)r-   r.   r6   history_datar4   s        r0   pushzHistoryManager.push0   s     !0099;;)))R856w<$**$tzzkm,G>tL!!--g->>> < 	?s"   B=B9BB=3B;4B=;B=c                  K   | j                   j                          d {   }|j                  dg       }|sy |j                         }|d   }|d   }|s$| j                   j	                  i        d {    n$| j                   j                  |       d {    t        j                  j                  d||       t        ||      S 7 7 Y7 6w)Nr4   r.   r6   r7   z!Pop state=%s data=%s from historyr5   )
r,   r8   r9   popset_datar>   r   r<   r=   r   )r-   r?   r4   recordr.   r6   s         r0   rB   zHistoryManager.pop:   s     !0099;;)))R8wf~%%..r222%%11'1BBB?M"T:: < 3Bs4   CCAC4C5$CC3CCCc                   K   | j                   j                          d {   }|j                  dg       }|sy t        di |d   S 7 'w)Nr4    r,   r8   r9   r   )r-   r?   r4   s      r0   getzHistoryManager.getI   sL     !0099;;)))R8"1WR[11	 <s   A
A(A
c                   K   | j                   j                          d {   }|j                  dg       }|D cg c]  }t        di | c}S 7 /c c}w w)Nr4   rG   rH   )r-   r?   r4   items       r0   allzHistoryManager.allP   sQ     !0099;;)))R88?@#+d+@@ <@s    AAAAAAc                   K   t         j                  j                  d       | j                  j	                  i        d {    y 7 w)NzClear history)r   r<   r=   r,   rC   r-   s    r0   clearzHistoryManager.clearU   s2     O,!!**2...s   >A AAc                   K   | j                   j                          d {   }| j                   j                          d {   }| j                  ||       d {    y 7 A7 !7 	wN)r+   	get_stater8   r@   r-   r.   r6   s      r0   snapshotzHistoryManager.snapshotY   sQ     kk++--[[))++iit$$$ .+$s3   A(A"!A(A$A(A&A($A(&A(c                   K   | j                   j                  |       d {    | j                   j                  |       d {    y 7 (7 wrQ   )r+   	set_staterC   rS   s      r0   
_set_statezHistoryManager._set_state^   s?     kk##E***kk""4((( 	+(s!   AA
"AAAAc                ^  K   | j                          d {   }|s| j                  d i        d {    y t        j                  j	                  d|j
                  |j                         | j                  |j
                  |j                         d {    |j
                  S 7 7 v7 w)NzRollback to state=%s data=%s)rB   rW   r   r<   r=   r.   r6   )r-   previous_states     r0   rollbackzHistoryManager.rollbackb   s     #xxz)//$+++*  	

 oon22N4G4GHHH### *+ 	Is2   B-B'B-B)A#B-B+B-)B-+B-N)scenes_history
   )r.   r   r'   strr/   int)r.   Optional[str]r6   Dict[str, Any]returnNone)ra   zOptional[MemoryStorageRecord])ra   zList[MemoryStorageRecord]ra   rb   )ra   r_   )__name__
__module____qualname__r1   r@   rB   rI   rL   rO   rT   rW   rZ   rG   r2   r0   r%   r%   (   s0    
?;2A
/%
)$r2   r%   c                  d    e Zd Z	 	 d
	 	 	 	 	 	 	 	 	 ddZddZddZddZddZddZddZ	dd	Z
y)ObserverDecoratorNc                <    || _         || _        || _        || _        y rQ   )namefiltersactionafter)r-   rj   rk   rl   rm   s        r0   r1   zObserverDecorator.__init__r   s      	
r2   c                    t        |dd       }|sg }t        |d|       |j                  t        | j                  || j
                  | j                               y )N__aiogram_handler__rj   handlerrk   rm   )getattrsetattrr:   HandlerContainerrj   rk   rm   )r-   targethandlerss      r0   _wrap_filterzObserverDecorator._wrap_filter~   sR    6#8$?HF18<YYjj		
r2   c                    | j                   J d       t        |dd       }|t        t              }t	        |d|       t        |      || j                      | j                  <   y )NzScene action is not specified__aiogram_action__)rl   rr   r   dictrs   r   rj   )r-   ru   rl   s      r0   _wrap_actionzObserverDecorator._wrap_action   s_    {{&G(GG&!5t<> &FF0&9)7)?t{{DII&r2   c                    t        j                  |      r2| j                  | j                  |       |S | j	                  |       |S t        d      )Nz"Only function or method is allowed)inspect
isfunctionrl   rw   r{   	TypeErrorr-   ru   s     r0   __call__zObserverDecorator.__call__   sT    f%{{"!!&)
  !!&)  @AAr2   c                `    t        | j                  | j                  t        j                        S rQ   )ActionContainerrj   rk   SceneActionleaverN   s    r0   r   zObserverDecorator.leave   s    tyy$,,8I8IJJr2   c                b    t        | j                  | j                  t        j                  |      S rQ   )r   rj   rk   r   enterr   s     r0   r   zObserverDecorator.enter   s!    tyy$,,8I8I6RRr2   c                `    t        | j                  | j                  t        j                        S rQ   )r   rj   rk   r   exitrN   s    r0   r   zObserverDecorator.exit       tyy$,,8H8HIIr2   c                `    t        | j                  | j                  t        j                        S rQ   )r   rj   rk   r   backrN   s    r0   r   zObserverDecorator.back   r   r2   )NN)
rj   r]   rk   ztuple[CallbackType, ...]rl   zSceneAction | Nonerm   Optional[After]ra   rb   )ru   zType[Scene] | CallbackTypera   rb   )ru   r   ra   rb   )ru   r   ra   r   )ra   r   )ru   Type[Scene]ra   r   )rd   re   rf   r1   rw   r{   r   r   r   r   r   rG   r2   r0   rh   rh   q   sg    
 &*!%

 *
 #	

 
 


@KSJJr2   rh   c                  D    e Zd Z e       Z e       Z e       Z e       Zy)r   N)rd   re   rf   r   r   r   r   r   rG   r2   r0   r   r      s    FEFE6D6Dr2   r   c                  2    e Zd Z	 d	 	 	 	 	 	 	 	 	 ddZddZy)r   Nc                <    || _         || _        || _        || _        y rQ   )rj   rk   rl   ru   )r-   rj   rk   rl   ru   s        r0   r1   zActionContainer.__init__   s      	r2   c                  K   | j                   t        j                  k(  r0| j                  $|j	                  | j                         d {    y | j                   t        j
                  k(  r|j                          d {    y | j                   t        j                  k(  r|j                          d {    y | j                   t        j                  k(  r|j                          d {    y y 7 7 t7 @7 wrQ   )rl   r   r   ru   gotor   r   r   r-   wizards     r0   executezActionContainer.execute   s     ;;++++0G++dkk***[[K---,,.  [[K,,,++-[[K,,,++- - + sH   AC;
C35C; C55C;6C775C;,C9-C;5C;7C;9C;rQ   )
rj   r]   rk   Tuple[CallbackType, ...]rl   r   ru   (Optional[Union[Type[Scene], State, str]]ra   rb   r   SceneWizardra   rb   )rd   re   rf   r1   r   rG   r2   r0   r   r      sB     <@

 *
 	

 9
 

 r2   r   c                  *    e Zd Z	 d	 	 	 	 	 	 	 	 	 ddZy)rt   Nc                <    || _         || _        || _        || _        y rQ   rp   )r-   rj   rq   rk   rm   s        r0   r1   zHandlerContainer.__init__   s      	
r2   rQ   )
rj   r]   rq   r   rk   r   rm   r   ra   rb   )rd   re   rf   r1   rG   r2   r0   rt   rt      s<     "&

 
 *	

 
 

r2   rt   c                  p    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<   y)SceneConfigr_   r.   zList[HandlerContainer]rv   z,Dict[SceneAction, Dict[str, CallableObject]]actionsNzOptional[bool]reset_data_on_enterreset_history_on_entercallback_query_without_stater"   attrs_resolver)	rd   re   rf   __annotations__r   r   r   r#   r   rG   r2   r0   r   r      sW    $$99*..#-1N1&37 .7,)FN&Fr2   r   c                    K   y wrQ   rG   )argskwargss     r0   _empty_handlerr      s	        c                  J    e Zd Z	 d	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZd	dZd
dZy)SceneHandlerWrapperNc                @    || _         t        |      | _        || _        y rQ   )r<   r   rq   rm   )r-   r<   rq   rm   s       r0   r1   zSceneHandlerWrapper.__init__   s     
%g.
r2   c           
       K   |d   }|d   }|d   }| j                  t        | j                   j                  |||j                  ||            } | j                  j
                  ||fi | d {   }| j                  rYt        dd| j                  j                  | j                  j                         }|j                  |j                         d {    |S 7 k7 w)Nr.   scenesevent_updatescene_configmanagerr.   update_typeeventr6   r   rm   rG   )r<   r   __scene_config__
event_typerq   callrm   r   rl   r   r   )	r-   r   r   r.   r   r   r<   resultaction_containers	            r0   r   zSceneHandlerWrapper.__call__  s     
 #7O &x 0%n5

!ZZ88(33  	
 )t||((@@@::.

!!

  	  #**5<<888 A 9s%   A0C"2C3A$C"C C" C"c                    | S rQ   rG   rN   s    r0   	__await__zSceneHandlerWrapper.__await__!  s    r2   c                    d| j                    d| j                  j                   }| j                  r|d| j                   z  }|dz  }|S )NzSceneHandlerWrapper(z, z, after=))r<   rq   callbackrm   )r-   r   s     r0   __str__zSceneHandlerWrapper.__str__$  sM    '

|2dll6K6K5LM::--F#r2   rQ   )r<   r   rq   r   rm   r   ra   rb   )r   r    r   r	   ra   r	   )ra   r   )ra   r]   )rd   re   rf   r1   r   r   r   rG   r2   r0   r   r      s]    
 "&	  	
 
  
	>r2   r   c                  z     e Zd ZU dZded<   	 	 	 	 	 d	dZd
 fdZedd       Zeddd       Z	edd       Z
 x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   c                4    || _         | | j                   _        y rQ   )r   r<   r   s     r0   r1   zScene.__init__=  s      r2   c           	        |j                  dd       }|j                  dd       }|j                  dd       }|j                  dd       }|j                  dd       }t        |   di | g }t        t              }| j
                  D ]\  }	t        |	t              st        |	dd       }
|
s$||
j                  }||
j                  }||
j                  }|Q|
j                  }^ |t        } ||       D ]  \  }}t        |dd       x}r|j                  |       t        |t               r@|j#                  t%        |j&                  t(        |j*                  |j,                               t/        |d	      s|j0                  j3                         D ]  \  }}||   j5                  |         t7        ||t	        |      ||||
      | _        y )Nr.   r   r   r   r   r   ro   rm   ry   )r.   rv   r   r   r   r   r   rG   )rB   super__init_subclass__r   rz   	__bases__
issubclassr   rr   r   r   r   r   r#   extend
isinstancerh   r:   rt   rj   r   rk   rm   hasattrry   itemsupdater   r   )clsr   
state_namer   r   r   r   rv   r   baseparent_scene_configrj   valuescene_handlersrl   action_handlers	__class__s                   r0   r   zScene.__init_subclass__D  s   ZZ.
$jj)>E!',Dd!K'-zz2PRV'W$$4d;!+F++-GRSWGXMM 	DDdE*")$0BD"I&"*&9&M&M#%-)<)S)S&+3/B/_/_,%!4!C!C	D" !:N)#. 	<KD%!(0Et!LL~L/%!23$

&#kk	 u23/4/G/G/M/M/O <+FOFO**?;<	<   +M 3#9)E) 
r2   c                   | j                   }t               }|j                  D ]  } |j                  |j                     j
                  t        | |j                  |j                        g|j                  dt        |j                        i |j                  |j                          |D ]E  }|j                  r|dk(  r|j                  |   j                  t        |j                               G y)z^
        Adds the scene to the given router.

        :param router:
        :return:
        r   flagscallback_queryN)r   setrv   	observersrj   registerr   rq   rm   rk   r   addr   filterr   r.   )r   routerr   used_observersrq   observer_names         r0   add_to_routerzScene.add_to_router~  s     ++#,, 
	-G3FW\\*33#OO!--  0@ w||,
	- , 	TM88]N^=^]+22;|?Q?Q3RS	Tr2   c                    |3d| j                    d| j                   d| j                  j                  }t	        |      }| j                  |       |S )zM
        Returns the scene as a router.

        :return: new router
        zScene '.z' for state rj   )re   rf   r   r.   r   r   )r   rj   r   s      r0   	as_routerzScene.as_router  sb     <#..)3+;+;*< = 1177:<  T"&!r2   c                (     	 	 	 	 	 	 	 	 d f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"))
        c                P   K    |j                   fi i | d {    y 7 wrQ   )r   )r   r   middleware_kwargsr   handler_kwargss      r0   enter_to_scene_handlerz0Scene.as_handler.<locals>.enter_to_scene_handler  s.      &,,sN&M&M;L&MNNNs   &$&)r   r    r   ScenesManagerr   r	   ra   rb   rG   )r   r   r   s   `` r0   
as_handlerzScene.as_handler  s5    	O!	O+8	OOR	O	O
 &%r2   r   r   r	   ra   rb   r   r   ra   rb   rQ   )rj   r_   ra   r   )r   r	   ra   r   )rd   re   rf   __doc__r   r1   r   classmethodr   r   r   __classcell__)r   s   @r0   r   r   ,  sn     ,+!! 
!8
t T T6   & &r2   r   c                      e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 ddZddZdddZddZddZddZ	ddZ
dd	Zdd
ZddZedd       Zedd       ZdddZ	 d	 	 	 	 	 ddZddZy) r   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.

    c                f    || _         || _        || _        || _        || _        || _        d| _        y)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   r6   r<   )r-   r   r   r.   r   r   r6   s          r0   r1   zSceneWizard.__init__  s7    & )
&
	&*
r2   c                :  K   t         j                  j                  d| j                  j                         | j                  j
                  r#| j                  j                  i        d{    | j                  j                  r,| j                  j                  j                          d{    | j                  j                  | j                  j                         d{     | j                  t        j                  fi | d{    y7 7 g7 27 w)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   r4   rO   rV   
_on_actionr   r   r-   r   s     r0   r   zSceneWizard.enter  s      	/1B1B1H1HI00**%%b)))33,,&&,,...jj""4#4#4#:#:;;;dook//:6:::	 *.;:sI   A)D+D,AD-D.6D$D%(DDDDDDc                *  K   t         j                  j                  d| j                  j                         |r,| j
                  j                  j                          d{     | j                  t        j                  fi | d{    y7 .7 w)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   r4   rT   r   r   r   )r-   _with_historyr   s      r0   r   zSceneWizard.leave  sp      	.0A0A0G0GH,,&&//111dook//:6::: 2:s$   AB B!(B	B
BBc                v  K   t         j                  j                  d| j                  j                         | j
                  j                  j                          d{     | j                  t        j                  fi | d{     | j
                  j                  dddi| d{    y7 T7 -7 	w)z
        Exit the current scene and enter the default scene/state.

        :param kwargs: Additional keyword arguments.
        :return: None
        zExiting scene %rN_check_activeFrQ   )r   r<   r=   r   r.   r   r4   rO   r   r   r   r   r   s     r0   r   zSceneWizard.exit  s      	.0A0A0G0GHll""((***dook..9&999 dll  EUEfEEE 	+9Es6   AB9B3(B9B5%B9-B7.B95B97B9c                ^  K   t         j                  j                  d| j                  j                          | j
                  dddi| d{    | j                  j                  j                          d{   } | j                  j                  |fddi| d{    y7 X7 .7 	w)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   rG   )
r   r<   r=   r   r.   r   r   r4   rZ   r   )r-   r   	new_scenes      r0   r   zSceneWizard.back  s      	BDDUDUD[D[\djj7u7777,,..7799	 dll  J%J6JJJ 	89Js6   AB-B'+B-:B);&B-!B+"B-)B-+B-c                   K   | j                   j                  J d        | j                  | j                   j                  fi | d{    y7 w)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   s     r0   retakezSceneWizard.retake  sK        &&2R4RR2dii))//:6:::s   AA
AAc                   K    | j                   di | d{     | j                  j                  |fddi| d{    y7 ,7 w)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   FrG   )r   r   r   )r-   r<   r   s      r0   r   zSceneWizard.goto'  sL      djj"6""" dll  FeFvFFF 	#Fs    A	A&A	A A	A	c                  K   | j                   st        d      t        j                   j                  d|j                  | j
                  j                         | j
                  j                  j                  |i       }|s@t        j                   j                  d|j                  | j
                  j                         y| j                  }||vrAt        j                   j                  d|j                  || j
                  j                         y ||   j                  | j                   | j                  fi i | j                  | d {    y7 w)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=   rj   r   r.   r   rI   r   r   r   r6   )r-   rl   r   action_configr   s        r0   r   zSceneWizard._on_action6  s    zz !;<<8&++tGXGXG^G^_))1155fbAMM16;;@Q@Q@W@W %%
]*MM>!!''	 ,mJ',,TZZ_G^$))G^W]G^___ 	`s   EEEEc                X   K   | j                   j                  |       d{    y7 w)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
        r6   N)r.   rC   )r-   r6   s     r0   rC   zSceneWizard.set_dataO  s#      jj!!t!,,,s    *(*c                R   K   | j                   j                          d{   S 7 w)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   rN   s    r0   r8   zSceneWizard.get_dataX  s!      ZZ((****s   '%'c                   K   yw)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.
        NrG   )r-   r)   s     r0   	get_valuezSceneWizard.get_value`  s      	r   c                   K   yw)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.
        NrG   r-   r)   defaults      r0   r  zSceneWizard.get_valuek  s      	r   Nc                V   K   | j                   j                  ||       d {   S 7 wrQ   )r.   r  r	  s      r0   r  zSceneWizard.get_valuew  s#     ZZ))#w7777s    )')c                |   K   |r|j                  |       | j                  j                  |       d{   S 7 w)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-   r6   r   s      r0   r>   zSceneWizard.update_dataz  s5      MM$ZZ+++8888s   3<:<c                B   K   | j                  i        d{    y7 w)z9
        Clears the data.

        :return: None
        N)rC   rN   s    r0   
clear_datazSceneWizard.clear_data  s      mmBs   )r   r   r   r   r.   r   r   r]   r   r    r6   r`   r   T)r   boolr   r	   ra   rb   )r<   zUnion[Type[Scene], State, str]r   r	   ra   rb   )rl   r   r   r	   ra   r  )r6   zMapping[str, Any]ra   rb   )ra   r`   )r)   r]   ra   Optional[Any])r)   r]   r
  r	   ra   r	   rQ   )r)   r]   r
  r  ra   r  )r6   zOptional[Mapping[str, Any]]r   r	   ra   r`   rc   )rd   re   rf   r   r1   r   r   r   r   r   r   r   rC   r8   r   r  r>   r  rG   r2   r0   r   r     s    +!+ + 	+
 + + +8;";
F
K;G2-+   	 	8 379/9BE9	9 r2   r   c                  b    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 ddZd	dZd
dZ	 d	 	 	 	 	 	 	 ddZddZy)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.
    c                ~    || _         || _        || _        || _        || _        t        | j                        | _        y rQ   )registryr   r   r.   r6   r%   r4   )r-   r  r   r   r.   r6   s         r0   r1   zScenesManager.__init__  s8     !&

	%djj1r2   c           
        K   | j                   j                  |      } |t        |j                  | | j                  | j
                  | j                  | j                              S w)Nr   r   )r  rI   r   r   r.   r   r   r6   )r-   
scene_types     r0   
_get_scenezScenesManager._get_scene  sY     ]]&&z2
'88jj ,,jjYY	
 		
s   A&A(c                   K   | j                   j                          d {   }	 | j                  |       d {   S 7 7 # t        $ r Y y w xY wwrQ   )r.   rR   r  r   )r-   r.   s     r0   _get_active_scenezScenesManager._get_active_scene  sL     jj**,,	/// -/ 		s@   A?AA AA AA 	AAAAc                  K   |r>| j                          d{   }|$ |j                  j                  di | d{    	 | j                  |       d{   } |j                  j                  di | d{    y7 i7 E7 -7 # t
        $ r* | | j                  j                  d       d{  7   Y yw xY ww)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
        NrG   )r  r   r   r  r   r   r.   rV   )r-   r  r   r   active_scener<   s         r0   r   zScenesManager.enter  s      !%!7!7!99L'.l))..8888	///*55E %%,,$$.v... :8 6 /  	-%**&&t,,,	-ss   C B%C BC B
 BB
 C <B=C C B
 C 
*B=4B75B=:C <B==C c                   K   | j                          d{   }|sy |j                  j                  di | d{    y7 ,7 w)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
        NrG   )r  r   r   )r-   r   r<   s      r0   closezScenesManager.close  sG      ,,..ell)&))) / 	*s   AA&AAAAN)r  SceneRegistryr   r]   r   r    r.   r   r6   r`   ra   rb   )r  r   ra   r   )ra   zOptional[Scene]r  )r  r   r   r  r   r	   ra   rb   r   )	rd   re   rf   r   r1   r  r  r   r  rG   r2   r0   r   r     s    
22 2 	2
 2 2 
2 
 #/</ / 	/
 
/:
*r2   r   c                  p    e Zd ZdZdddZddZ	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 ddZddddZdd	Z	dd
Z
y)r  zJ
    A class that represents a registry for scenes in a Telegram bot.
    c                P    || _         || _        i | _        | j                  |       y)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   register_on_add_scenes_setup_middleware)r-   r   r!  s      r0   r1   zSceneRegistry.__init__  s(     .9;v&r2   c                   t        |t              r&|j                  j                  | j                         y |j
                  j                         D ],  }|j                  dv r|j                  | j                         . y )N>   errorr   )	r   r   r   outer_middleware_update_middlewarer   values
event_name_middleware)r-   r   observers      r0   r#  zSceneRegistry._setup_middleware  sm    fj) MM**4+B+BC((//1 	8H""&99%%d&6&67	8r2   c                   K   t        |t              sJ d       t        | |j                  |j                  |d   |      |d<    |||       d {   S 7 w)Nz Event must be an Update instancer.   r  r   r   r.   r6   r   )r   r!   r   r   r   )r-   rq   r   r6   s       r0   r'  z SceneRegistry._update_middleware  s^      %(L*LL(&((++w-
X UD))))s   AAAAc                z   K   |d   }t        | |j                  ||d   |      |d<    |||       d {   S 7 w)Nr   r.   r-  r   )r   r   )r-   rq   r   r6   r   s        r0   r*  zSceneRegistry._middleware  sN      n-&))w-
X UD))))s   2;9;N)r   c                  |st        d      |D ]  }|j                  j                  | j                  v r#t	        d|j                  j                  d      || j                  |j                  j                  <   |r |j                  |j                                | j                  s| j                  j                  |j                                 y)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   r<   s       r0   r   zSceneRegistry.add$  s    $ CDD 	>E%%++t||;$'(>(>(D(D'GW  :?DLL//556%%eoo&78%%**5??+<=	>r2   c                <     | j                   |d| j                  i y)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   s     r0   r   zSceneRegistry.registerF  s     	&--r2   c                B   t        j                  |      r&t        |t              r|j                  j
                  }t        |t              r|j
                  }|t        |t              st        d      	 | j                  |   S # t        $ r t        d|d      w xY 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.

        z4Scene must be a subclass of Scene, State or a stringzScene z is not registered)r}   isclassr   r   r   r.   r   r   r]   r   r"  KeyError)r-   r<   s     r0   rI   zSceneRegistry.getO  s      ??5!j&>**00EeU#KKEZs%; !WXX	G<<&& 	G 6%2D!EFF	Gs   6B Br  )r   r   r!  r  ra   rb   r   )rq   z"NextMiddlewareType[TelegramObject]r   r    r6   r`   ra   r	   )r   r   r   zOptional[Router]ra   rb   )r   r   ra   rb   )r<   r   ra   r   )rd   re   rf   r   r1   r#  r'  r*  r   r   rI   rG   r2   r0   r  r    s    '
8*3* * 	*
 
*"*3* * 	*
 
*  DH  >D.Gr2   r  c                  \    e Zd ZU ded<   dZded<   ed	d       Zed	d       Zed
d       Zy)Afterr   rl   Nr   r<   c                0     | t         j                        S Nrl   )r   r   r   s    r0   r   z
After.exitq      +**++r2   c                0     | t         j                        S r9  )r   r   r;  s    r0   r   z
After.backu  r<  r2   c                2     | t         j                  |      S )N)rl   r<   )r   r   )r   r<   s     r0   r   z
After.gotoy  s    +++599r2   )ra   r7  )r<   r   ra   r7  )	rd   re   rf   r   r<   r   r   r   r   rG   r2   r0   r7  r7  l  sM    6:E3:, , , , : :r2   r7  c                  L    e Zd Zd	dZdd	 	 	 	 	 d
dZddZddZddZddZy)ObserverMarkerc                    || _         y rQ   r   )r-   rj   s     r0   r1   zObserverMarker.__init__  s	    	r2   Nr   c               2    t        | j                  ||      S )Nr   )rh   rj   )r-   rm   rk   s      r0   r   zObserverMarker.__call__  s    
 !II
 	
r2   c                N    t        | j                  |t        j                        S r9  )rh   rj   r   r   )r-   rk   s     r0   r   zObserverMarker.enter  s     GK<M<MNNr2   c                N    t        | j                  dt        j                        S NrG   r:  )rh   rj   r   r   rN   s    r0   r   zObserverMarker.leave  s     B{7H7HIIr2   c                N    t        | j                  dt        j                        S rE  )rh   rj   r   r   rN   s    r0   r   zObserverMarker.exit       B{7G7GHHr2   c                N    t        | j                  dt        j                        S rE  )rh   rj   r   r   rN   s    r0   r   zObserverMarker.back  rG  r2   )rj   r]   ra   rb   )rk   r   rm   r   ra   rh   )rk   r   ra   rh   )ra   rh   )	rd   re   rf   r1   r   r   r   r   r   rG   r2   r0   r@  r@  ~  sE     "&	
	
 	
 
		
OJIIr2   r@  c                      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y)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)rd   re   rf   r   r@  rK  rL  rM  rN  rO  rP  r   rQ  rR  rS  rT  rU  rV  rW  rG   r2   r0   rJ  rJ    s    6 Y'G#$45N!.1L()>?!.1L)*@A#$45N#$45N'(<=&!D /K#$45N /K&':;r2   rJ  )r   r	   r   r	   ra   rb   )E
__future__r   r}   collectionsr   dataclassesr   r   enumr   r   typingr	   r
   r   r   r   r   r   r   r   r   typing_extensionsr   aiogramr   aiogram.dispatcher.dispatcherr   aiogram.dispatcher.event.basesr    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#   r%   rh   r   r   rt   r   r   r   r   r   r   r  r7  r@  rJ  onrG   r2   r0   <module>rl     s%   "  # *    #  4 = I > , - ' * # : 0F$ F$R9J 9Jx$    0    0	2 2jL& L&^S  S lQ* Q*hDG DGN : : :"I I8)< )<X Zr2   