o
    ҷh                     @  s   d dl mZ ddlmZmZ d dlmZ d dlZd dlZddl	m
Z
 ddl	mZ G dd	 d	ejZeG d
d dZeG dd dZd!ddZd!ddZd"ddZd!ddZedeG dd dZedeG dd  d ZdS )#    )annotations   )event_classT_JSON_DICT)	dataclassN)network)service_workerc                   @  s<   e Zd ZdZdZdZdZdZdZdZ	dd	 Z
ed
d ZdS )ServiceNamez
    The Background Service that will be associated with the commands/events.
    Every Background Service operates independently, but they share the same
    API.
    backgroundFetchbackgroundSyncpushMessagingnotificationspaymentHandlerperiodicBackgroundSyncc                 C  s   | j S N)value)self r   m/var/www/html/venv/lib/python3.10/site-packages/selenium/webdriver/common/devtools/v118/background_service.pyto_json   s   zServiceName.to_jsonc                 C  s   | |S r   r   clsjsonr   r   r   	from_json    s   zServiceName.from_jsonN)__name__
__module____qualname____doc__BACKGROUND_FETCHBACKGROUND_SYNCPUSH_MESSAGINGNOTIFICATIONSPAYMENT_HANDLERPERIODIC_BACKGROUND_SYNCr   classmethodr   r   r   r   r   r	      s    r	   c                   @  s6   e Zd ZU dZded< ded< dd Zedd Zd	S )
EventMetadatazJ
    A key-value pair for additional event information to pass along.
    strkeyr   c                 C  s   t  }| j|d< | j|d< |S )Nr'   r   )dictr'   r   r   r   r   r   r   r   .   s   

zEventMetadata.to_jsonc                 C  s   | t |d t |d dS )Nr'   r   )r'   r   )r&   r   r   r   r   r   4   s   

zEventMetadata.from_jsonN)r   r   r   r   __annotations__r   r$   r   r   r   r   r   r%   %   s   
 r%   c                   @  sb   e Zd ZU ded< ded< ded< ded< ded	< ded
< ded< ded< dd Zedd ZdS )BackgroundServiceEventznetwork.TimeSinceEpoch	timestampr&   originzservice_worker.RegistrationIDservice_worker_registration_idr	   service
event_nameinstance_idztyping.List[EventMetadata]event_metadatastorage_keyc                 C  sp   t  }| j |d< | j|d< | j |d< | j |d< | j|d< | j|d< dd | jD |d	< | j	|d
< |S )Nr,   r-   serviceWorkerRegistrationIdr/   	eventName
instanceIdc                 S  s   g | ]}|  qS r   )r   .0ir   r   r   
<listcomp>^   s    z2BackgroundServiceEvent.to_json.<locals>.<listcomp>eventMetadata
storageKey)
r(   r,   r   r-   r.   r/   r0   r1   r2   r3   r)   r   r   r   r   V   s   



zBackgroundServiceEvent.to_jsonc                 C  sh   | t j|d t|d tj|d t|d t|d t|d dd |d	 D t|d
 dS )Nr,   r-   r4   r/   r5   r6   c                 S  s   g | ]}t |qS r   )r%   r   r7   r   r   r   r:   k   s    z4BackgroundServiceEvent.from_json.<locals>.<listcomp>r;   r<   )r,   r-   r.   r/   r0   r1   r2   r3   )r   TimeSinceEpochr   r&   r   RegistrationIDr	   r   r   r   r   r   b   s   



z BackgroundServiceEvent.from_jsonN)r   r   r   r*   r   r$   r   r   r   r   r   r+   <   s   
 r+   r/   return0typing.Generator[T_JSON_DICT, T_JSON_DICT, None]c                 c  (    t  }|  |d< d|d}|V }dS )zE
    Enables event updates for the service.

    :param service:
    r/   z BackgroundService.startObservingmethodparamsNr(   r   r/   rD   cmd_dictr   r   r   r   start_observingp      
rH   c                 c  rA   )zF
    Disables event updates for the service.

    :param service:
    r/   zBackgroundService.stopObservingrB   NrE   rF   r   r   r   stop_observing   rI   rJ   should_recordboolc                 c  s0    t  }| |d< | |d< d|d}|V }dS )za
    Set the recording state for the service.

    :param should_record:
    :param service:
    shouldRecordr/   zBackgroundService.setRecordingrB   NrE   )rK   r/   rD   rG   r   r   r   r   set_recording   s   

rN   c                 c  rA   )zF
    Clears all stored data for the service.

    :param service:
    r/   zBackgroundService.clearEventsrB   NrE   rF   r   r   r   clear_events   rI   rO   z'BackgroundService.recordingStateChangedc                   @  s0   e Zd ZU dZded< ded< edd	d
ZdS )RecordingStateChangedzK
    Called when the recording state for the service has been updated.
    rL   is_recordingr	   r/   r   r   r?   c                 C  s   | t |d t|d dS )NisRecordingr/   )rQ   r/   )rL   r	   r   r   r   r   r   r      s   
zRecordingStateChanged.from_jsonN)r   r   r?   rP   r   r   r   r   r*   r$   r   r   r   r   r   rP      s   
 rP   z0BackgroundService.backgroundServiceEventReceivedc                   @  s(   e Zd ZU dZded< ed
ddZd	S )BackgroundServiceEventReceivedz
    Called with all existing backgroundServiceEvents when enabled, and all new
    events afterwards if enabled and recording.
    r+   background_service_eventr   r   r?   c                 C  s   | t |d dS )NbackgroundServiceEvent)rU   )r+   r   r   r   r   r   r      s   z(BackgroundServiceEventReceived.from_jsonN)r   r   r?   rT   rS   r   r   r   r   rT      s
   
 rT   )r/   r	   r?   r@   )rK   rL   r/   r	   r?   r@   )
__future__r   utilr   r   dataclassesr   enumtyping r   r   Enumr	   r%   r+   rH   rJ   rN   rO   rP   rT   r   r   r   r   <module>   s,   
3


