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

Actions and events related to the inspected page belong to the page domain.
https://chromedevtools.github.io/devtools-protocol/tot/Page/

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

from typing import Literal

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


class DomContentEventFired(CDPEvent):

    timestamp: Network.MonotonicTime


class FileChooserOpened(CDPEvent):
    """ Emitted only when `page.interceptFileChooser` is enabled. """

    frameId: Page.FrameId | None = None  # experimental
    mode: Literal['selectSingle', 'selectMultiple']
    backendNodeId: DOM.BackendNodeId | None = None  # experimental


class FrameAttached(CDPEvent):
    """ Fired when frame has been attached to its parent. """

    frameId: Page.FrameId
    parentFrameId: Page.FrameId
    stack: Runtime.StackTrace | None = None


class FrameClearedScheduledNavigation(CDPEvent):
    """ Fired when frame no longer has a scheduled navigation. """

    frameId: Page.FrameId


class FrameDetached(CDPEvent):
    """ Fired when frame has been detached from its parent. """

    frameId: Page.FrameId
    reason: Literal['remove', 'swap'] | None = None  # experimental


class FrameSubtreeWillBeDetached(CDPEvent):
    """ Fired before frame subtree is detached. Emitted before any frame of the
    subtree is actually detached. """

    frameId: Page.FrameId


class FrameNavigated(CDPEvent):
    """ Fired once navigation of the frame has completed. Frame is now associated with the new loader. """

    frame: Page.Frame
    type: Page.NavigationType | None = None  # experimental


class DocumentOpened(CDPEvent):
    """ Fired when opening document to write to. """

    frame: Page.Frame


class FrameResized(CDPEvent):

    ...


class FrameStartedNavigating(CDPEvent):
    """ Fired when a navigation starts. This event is fired for both
    renderer-initiated and browser-initiated navigations. For renderer-initiated
    navigations, the event is fired after `frameRequestedNavigation`.
    Navigation may still be cancelled after the event is issued. Multiple events
    can be fired for a single navigation, for example, when a same-document
    navigation becomes a cross-document navigation (such as in the case of a
    frameset). """

    frameId: Page.FrameId
    url: str
    loaderId: Network.LoaderId
    navigationType: Literal['reload', 'reloadBypassingCache', 'restore', 'restoreWithPost', 'historySameDocument', 'historyDifferentDocument', 'sameDocument', 'differentDocument']


class FrameRequestedNavigation(CDPEvent):
    """ Fired when a renderer-initiated navigation is requested.
    Navigation may still be cancelled after the event is issued. """

    frameId: Page.FrameId
    reason: Page.ClientNavigationReason
    url: str
    disposition: Page.ClientNavigationDisposition


class FrameScheduledNavigation(CDPEvent):
    """ Fired when frame schedules a potential navigation. """

    frameId: Page.FrameId
    delay: float
    reason: Page.ClientNavigationReason
    url: str


class FrameStartedLoading(CDPEvent):
    """ Fired when frame has started loading. """

    frameId: Page.FrameId


class FrameStoppedLoading(CDPEvent):
    """ Fired when frame has stopped loading. """

    frameId: Page.FrameId


class DownloadWillBegin(CDPEvent):
    """ Fired when page is about to start a download.
    Deprecated. Use Browser.downloadWillBegin instead. """

    frameId: Page.FrameId
    guid: str
    url: str
    suggestedFilename: str


class DownloadProgress(CDPEvent):
    """ Fired when download makes progress. Last call has |done| == true.
    Deprecated. Use Browser.downloadProgress instead. """

    guid: str
    totalBytes: float
    receivedBytes: float
    state: Literal['inProgress', 'completed', 'canceled']


class InterstitialHidden(CDPEvent):
    """ Fired when interstitial page was hidden """

    ...


class InterstitialShown(CDPEvent):
    """ Fired when interstitial page was shown """

    ...


class JavascriptDialogClosed(CDPEvent):
    """ Fired when a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload) has been
    closed. """

    frameId: Page.FrameId | None = None  # experimental
    result: bool
    userInput: str


class JavascriptDialogOpening(CDPEvent):
    """ Fired when a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload) is about to
    open. """

    url: str
    frameId: Page.FrameId | None = None  # experimental
    message: str
    type: Page.DialogType
    hasBrowserHandler: bool
    defaultPrompt: str | None = None


class LifecycleEvent(CDPEvent):
    """ Fired for lifecycle events (navigation, load, paint, etc) in the current
    target (including local frames). """

    frameId: Page.FrameId
    loaderId: Network.LoaderId
    name: str
    timestamp: Network.MonotonicTime


class BackForwardCacheNotUsed(CDPEvent):
    """ Fired for failed bfcache history navigations if BackForwardCache feature is enabled. Do
    not assume any ordering with the Page.frameNavigated event. This event is fired only for
    main-frame history navigation where the document changes (non-same-document navigations),
    when bfcache navigation fails. """

    loaderId: Network.LoaderId
    frameId: Page.FrameId
    notRestoredExplanations: list[Page.BackForwardCacheNotRestoredExplanation]
    notRestoredExplanationsTree: Page.BackForwardCacheNotRestoredExplanationTree | None = None


class LoadEventFired(CDPEvent):

    timestamp: Network.MonotonicTime


class NavigatedWithinDocument(CDPEvent):
    """ Fired when same-document navigation happens, e.g. due to history API usage or anchor navigation. """

    frameId: Page.FrameId
    url: str
    navigationType: Literal['fragment', 'historyApi', 'other']


class ScreencastFrame(CDPEvent):
    """ Compressed image data requested by the `startScreencast`. """

    data: str
    metadata: Page.ScreencastFrameMetadata
    sessionId: int


class ScreencastVisibilityChanged(CDPEvent):
    """ Fired when the page with currently enabled screencast was shown or hidden `. """

    visible: bool


class WindowOpen(CDPEvent):
    """ Fired when a new window is going to be opened, via window.open(), link click, form submission,
    etc. """

    url: str
    windowName: str
    windowFeatures: list[str]
    userGesture: bool


class CompilationCacheProduced(CDPEvent):
    """ Issued for every compilation cache generated. """

    url: str
    data: str
