
    >i                    t    d dl mZ d dlZd dlZd dlmZ erd dlmZ  ej                  e	      Z
 G d d      Zy)    )annotationsN)TYPE_CHECKING)Commandc                  0    e Zd ZdZddZddZd	dZd
dZy)CommandsManagerz
    Manages command lifecycle and ID assignment for CDP commands.

    Handles command future creation, ID generation, and response resolution
    for asynchronous command execution.
    c                J    i | _         d| _        t        j                  d       y)z,Initialize command manager with empty state.   zCommandsManager initializedN)_pending_commands_idloggerdebug)selfs    q/var/www/python/tenders/Scrapper/venv/lib/python3.12/site-packages/pydoll/connection/managers/commands_manager.py__init__zCommandsManager.__init__   s    <>23    c                   | j                   |d<   t        j                         }|| j                  | j                   <   | xj                   dz  c_         t        j                  d|d    d|j                  d              |S )z
        Create future for command and assign unique ID.

        Args:
            command: Command to prepare for execution.

        Returns:
            Future that resolves when command completes.
        idr	   zCreated future for command id=z method=method)r   asyncioFuturer
   r   r   get)r   commandfutures      r   create_command_futurez%CommandsManager.create_command_future   sp     !+1txx(A,WT]O8GKKPXDYCZ[	
 r   c                    || j                   v rD| j                   |   j                  |       | j                   |= t        j                  d|        yy)z(Resolve pending command with its result.zResolved command future id=N)r
   
set_resultr   r   )r   response_idresults      r   resolve_commandzCommandsManager.resolve_command.   sP    $000"";/::6B&&{3LL6{mDE 1r   c                l    || j                   v r&| j                   |= t        j                  d|        yy)zFRemove pending command without resolving (for timeouts/cancellations).zRemoved pending command id=N)r
   r   r   )r   
command_ids     r   remove_pending_commandz&CommandsManager.remove_pending_command5   s7    ///&&z2LL6zlCD 0r   N)returnNone)r   r   r#   zasyncio.Future)r   intr   str)r!   r%   )__name__
__module____qualname____doc__r   r   r   r"    r   r   r   r      s    4&FEr   r   )
__future__r   r   loggingtypingr   pydoll.protocol.baser   	getLoggerr'   r   r   r+   r   r   <module>r1      s5    "    ,			8	$,E ,Er   