"""
This file is generated by generator/run.py based on the Chrome DevTools Protocol.

Network domain allows tracking network activities of the page. It exposes information about http,
file, data and other requests and responses, their headers, bodies, timing, etc.
https://chromedevtools.github.io/devtools-protocol/tot/Network/

***************************************************
                    Events
***************************************************
"""
from __future__ import annotations

from typing import Literal

from cdpkit.protocol._types import (
    Network,
    Page,
)
from cdpkit.protocol.base import CDPEvent


class DataReceived(CDPEvent):
    """ Fired when data chunk was received over the network. """

    requestId: Network.RequestId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated
    dataLength: int  # deprecated
    encodedDataLength: int  # deprecated
    data: str | None = None  # experimental deprecated


class EventSourceMessageReceived(CDPEvent):
    """ Fired when EventSource message is received. """

    requestId: Network.RequestId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated
    eventName: str  # deprecated
    eventId: str  # deprecated
    data: str  # deprecated


class LoadingFailed(CDPEvent):
    """ Fired when HTTP request has failed to load. """

    requestId: Network.RequestId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated
    type: Network.ResourceType  # deprecated
    errorText: str  # deprecated
    canceled: bool | None = None  # deprecated
    blockedReason: Network.BlockedReason | None = None  # deprecated
    corsErrorStatus: Network.CorsErrorStatus | None = None  # deprecated


class LoadingFinished(CDPEvent):
    """ Fired when HTTP request has finished loading. """

    requestId: Network.RequestId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated
    encodedDataLength: float  # deprecated


class RequestIntercepted(CDPEvent):
    """ Details of an intercepted HTTP request, which must be either allowed, blocked, modified or
    mocked.
    Deprecated, use Fetch.requestPaused instead. """

    interceptionId: Network.InterceptionId  # deprecated
    request: Network.Request
    frameId: Page.FrameId  # deprecated
    resourceType: Network.ResourceType  # deprecated
    isNavigationRequest: bool  # deprecated
    isDownload: bool | None = None  # deprecated
    redirectUrl: str | None = None  # deprecated
    authChallenge: Network.AuthChallenge | None = None  # deprecated
    responseErrorReason: Network.ErrorReason | None = None  # deprecated
    responseStatusCode: int | None = None  # deprecated
    responseHeaders: Network.Headers | None = None  # deprecated
    requestId: Network.RequestId | None = None  # deprecated


class RequestServedFromCache(CDPEvent):
    """ Fired if request ended up loading from cache. """

    requestId: Network.RequestId  # deprecated


class RequestWillBeSent(CDPEvent):
    """ Fired when page is about to send HTTP request. """

    requestId: Network.RequestId  # deprecated
    loaderId: Network.LoaderId  # deprecated
    documentURL: str  # deprecated
    request: Network.Request  # deprecated
    timestamp: Network.MonotonicTime  # deprecated
    wallTime: Network.TimeSinceEpoch  # deprecated
    initiator: Network.Initiator  # deprecated
    redirectHasExtraInfo: bool | None = None  # experimental deprecated
    redirectResponse: Network.Response | None = None  # deprecated
    type: Network.ResourceType | None = None  # deprecated
    frameId: Page.FrameId | None = None  # deprecated
    hasUserGesture: bool | None = None  # deprecated


class ResourceChangedPriority(CDPEvent):
    """ Fired when resource loading priority is changed """

    requestId: Network.RequestId  # deprecated
    newPriority: Network.ResourcePriority  # deprecated
    timestamp: Network.MonotonicTime  # deprecated


class SignedExchangeReceived(CDPEvent):
    """ Fired when a signed exchange was received over the network """

    requestId: Network.RequestId  # deprecated
    info: Network.SignedExchangeInfo  # deprecated


class ResponseReceived(CDPEvent):
    """ Fired when HTTP response is available. """

    requestId: Network.RequestId  # deprecated
    loaderId: Network.LoaderId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated
    type: Network.ResourceType  # deprecated
    response: Network.Response  # deprecated
    hasExtraInfo: bool | None = None  # experimental deprecated
    frameId: Page.FrameId | None = None  # deprecated


class WebSocketClosed(CDPEvent):
    """ Fired when WebSocket is closed. """

    requestId: Network.RequestId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated


class WebSocketCreated(CDPEvent):
    """ Fired upon WebSocket creation. """

    requestId: Network.RequestId  # deprecated
    url: str  # deprecated
    initiator: Network.Initiator | None = None  # deprecated


class WebSocketFrameError(CDPEvent):
    """ Fired when WebSocket message error occurs. """

    requestId: Network.RequestId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated
    errorMessage: str  # deprecated


class WebSocketFrameReceived(CDPEvent):
    """ Fired when WebSocket message is received. """

    requestId: Network.RequestId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated
    response: Network.WebSocketFrame  # deprecated


class WebSocketFrameSent(CDPEvent):
    """ Fired when WebSocket message is sent. """

    requestId: Network.RequestId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated
    response: Network.WebSocketFrame  # deprecated


class WebSocketHandshakeResponseReceived(CDPEvent):
    """ Fired when WebSocket handshake response becomes available. """

    requestId: Network.RequestId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated
    response: Network.WebSocketResponse  # deprecated


class WebSocketWillSendHandshakeRequest(CDPEvent):
    """ Fired when WebSocket is about to initiate handshake. """

    requestId: Network.RequestId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated
    wallTime: Network.TimeSinceEpoch  # deprecated
    request: Network.WebSocketRequest  # deprecated


class WebTransportCreated(CDPEvent):
    """ Fired upon WebTransport creation. """

    transportId: Network.RequestId  # deprecated
    url: str  # deprecated
    timestamp: Network.MonotonicTime  # deprecated
    initiator: Network.Initiator | None = None  # deprecated


class WebTransportConnectionEstablished(CDPEvent):
    """ Fired when WebTransport handshake is finished. """

    transportId: Network.RequestId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated


class WebTransportClosed(CDPEvent):
    """ Fired when WebTransport is disposed. """

    transportId: Network.RequestId  # deprecated
    timestamp: Network.MonotonicTime  # deprecated


class DirectTCPSocketCreated(CDPEvent):
    """ Fired upon direct_socket.TCPSocket creation. """

    identifier: Network.RequestId
    remoteAddr: str
    remotePort: int  # deprecated
    options: Network.DirectTCPSocketOptions
    timestamp: Network.MonotonicTime
    initiator: Network.Initiator | None = None


class DirectTCPSocketOpened(CDPEvent):
    """ Fired when direct_socket.TCPSocket connection is opened. """

    identifier: Network.RequestId
    remoteAddr: str
    remotePort: int  # deprecated
    timestamp: Network.MonotonicTime
    localAddr: str | None = None
    localPort: int | None = None  # deprecated


class DirectTCPSocketAborted(CDPEvent):
    """ Fired when direct_socket.TCPSocket is aborted. """

    identifier: Network.RequestId
    errorMessage: str
    timestamp: Network.MonotonicTime


class DirectTCPSocketClosed(CDPEvent):
    """ Fired when direct_socket.TCPSocket is closed. """

    identifier: Network.RequestId
    timestamp: Network.MonotonicTime


class DirectTCPSocketChunkSent(CDPEvent):
    """ Fired when data is sent to tcp direct socket stream. """

    identifier: Network.RequestId
    data: str
    timestamp: Network.MonotonicTime


class DirectTCPSocketChunkReceived(CDPEvent):
    """ Fired when data is received from tcp direct socket stream. """

    identifier: Network.RequestId
    data: str
    timestamp: Network.MonotonicTime


class DirectUDPSocketCreated(CDPEvent):
    """ Fired upon direct_socket.UDPSocket creation. """

    identifier: Network.RequestId
    options: Network.DirectUDPSocketOptions
    timestamp: Network.MonotonicTime
    initiator: Network.Initiator | None = None


class DirectUDPSocketOpened(CDPEvent):
    """ Fired when direct_socket.UDPSocket connection is opened. """

    identifier: Network.RequestId
    localAddr: str
    localPort: int  # deprecated
    timestamp: Network.MonotonicTime
    remoteAddr: str | None = None
    remotePort: int | None = None  # deprecated


class DirectUDPSocketAborted(CDPEvent):
    """ Fired when direct_socket.UDPSocket is aborted. """

    identifier: Network.RequestId
    errorMessage: str
    timestamp: Network.MonotonicTime


class DirectUDPSocketClosed(CDPEvent):
    """ Fired when direct_socket.UDPSocket is closed. """

    identifier: Network.RequestId
    timestamp: Network.MonotonicTime


class DirectUDPSocketChunkSent(CDPEvent):
    """ Fired when message is sent to udp direct socket stream. """

    identifier: Network.RequestId
    message: Network.DirectUDPMessage
    timestamp: Network.MonotonicTime


class DirectUDPSocketChunkReceived(CDPEvent):
    """ Fired when message is received from udp direct socket stream. """

    identifier: Network.RequestId
    message: Network.DirectUDPMessage
    timestamp: Network.MonotonicTime


class RequestWillBeSentExtraInfo(CDPEvent):
    """ Fired when additional information about a requestWillBeSent event is available from the
    network stack. Not every requestWillBeSent event will have an additional
    requestWillBeSentExtraInfo fired for it, and there is no guarantee whether requestWillBeSent
    or requestWillBeSentExtraInfo will be fired first for the same request. """

    requestId: Network.RequestId  # deprecated
    associatedCookies: list[Network.AssociatedCookie]  # deprecated
    headers: Network.Headers  # deprecated
    connectTiming: Network.ConnectTiming | None = None  # experimental deprecated
    clientSecurityState: Network.ClientSecurityState | None = None  # deprecated
    siteHasCookieInOtherPartition: bool | None = None  # deprecated


class ResponseReceivedExtraInfo(CDPEvent):
    """ Fired when additional information about a responseReceived event is available from the network
    stack. Not every responseReceived event will have an additional responseReceivedExtraInfo for
    it, and responseReceivedExtraInfo may be fired before or after responseReceived. """

    requestId: Network.RequestId  # deprecated
    blockedCookies: list[Network.BlockedSetCookieWithReason]  # deprecated
    headers: Network.Headers  # deprecated
    resourceIPAddressSpace: Network.IPAddressSpace  # deprecated
    statusCode: int  # deprecated
    headersText: str | None = None  # deprecated
    cookiePartitionKey: Network.CookiePartitionKey | None = None  # experimental deprecated
    cookiePartitionKeyOpaque: bool | None = None  # deprecated
    exemptedCookies: list[Network.ExemptedSetCookieWithReason] | None = None  # deprecated


class ResponseReceivedEarlyHints(CDPEvent):
    """ Fired when 103 Early Hints headers is received in addition to the common response.
    Not every responseReceived event will have an responseReceivedEarlyHints fired.
    Only one responseReceivedEarlyHints may be fired for eached responseReceived event. """

    requestId: Network.RequestId  # deprecated
    headers: Network.Headers  # deprecated


class TrustTokenOperationDone(CDPEvent):
    """ Fired exactly once for each Trust Token operation. Depending on
    the type of the operation and whether the operation succeeded or
    failed, the event is fired before the corresponding request was sent
    or after the response was received. """

    status: Literal['Ok', 'InvalidArgument', 'MissingIssuerKeys', 'FailedPrecondition', 'ResourceExhausted', 'AlreadyExists', 'ResourceLimited', 'Unauthorized', 'BadResponse', 'InternalError', 'UnknownError', 'FulfilledLocally', 'SiteIssuerLimit']  # deprecated
    type: Network.TrustTokenOperationType
    requestId: Network.RequestId
    topLevelOrigin: str | None = None  # deprecated
    issuerOrigin: str | None = None  # deprecated
    issuedTokenCount: int | None = None  # deprecated


class PolicyUpdated(CDPEvent):
    """ Fired once security policy has been updated. """

    ...


class SubresourceWebBundleMetadataReceived(CDPEvent):
    """ Fired once when parsing the .wbn file has succeeded.
    The event contains the information about the web bundle contents. """

    requestId: Network.RequestId  # deprecated
    urls: list[str]  # deprecated


class SubresourceWebBundleMetadataError(CDPEvent):
    """ Fired once when parsing the .wbn file has failed. """

    requestId: Network.RequestId  # deprecated
    errorMessage: str  # deprecated


class SubresourceWebBundleInnerResponseParsed(CDPEvent):
    """ Fired when handling requests for resources within a .wbn file.
    Note: this will only be fired for resources that are requested by the webpage. """

    innerRequestId: Network.RequestId  # deprecated
    innerRequestURL: str  # deprecated
    bundleRequestId: Network.RequestId | None = None  # deprecated


class SubresourceWebBundleInnerResponseError(CDPEvent):
    """ Fired when request for resources within a .wbn file failed. """

    innerRequestId: Network.RequestId  # deprecated
    innerRequestURL: str  # deprecated
    errorMessage: str  # deprecated
    bundleRequestId: Network.RequestId | None = None  # deprecated


class ReportingApiReportAdded(CDPEvent):
    """ Is sent whenever a new report is added.
    And after 'enableReportingApi' for all existing reports. """

    report: Network.ReportingApiReport


class ReportingApiReportUpdated(CDPEvent):

    report: Network.ReportingApiReport


class ReportingApiEndpointsChangedForOrigin(CDPEvent):

    origin: str  # deprecated
    endpoints: list[Network.ReportingApiEndpoint]
