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

Runtime domain exposes JavaScript runtime by means of remote evaluation and mirror objects.
Evaluation results are returned as mirror object that expose object type, string representation
and unique identifier that can be used for further object reference. Original objects are
maintained in memory unless they are either explicitly released or are released along with the
other objects in their object group.
https://chromedevtools.github.io/devtools-protocol/tot/Runtime/

***************************************************
                    Methods
***************************************************
"""
from __future__ import annotations

from cdpkit.protocol._types import (
    Runtime,
)
from cdpkit.protocol.base import CDPMethod, InputModel, OutputModel


class AwaitPromiseInput(InputModel):

    promiseObjectId: Runtime.RemoteObjectId
    returnByValue: bool | None = None
    generatePreview: bool | None = None


class AwaitPromiseOutput(OutputModel):

    result: Runtime.RemoteObject
    exceptionDetails: Runtime.ExceptionDetails | None = None


class AwaitPromise(CDPMethod[AwaitPromiseOutput]):
    """ Add handler to promise with given promise object id. """

    INPUT_VALIDATOR = AwaitPromiseInput
    OUTPUT_VALIDATOR = AwaitPromiseOutput

    def __init__(
        self,
        *,
        promise_object_id: Runtime.RemoteObjectId,
        return_by_value: bool | None = None,
        generate_preview: bool | None = None
    ):
        super().__init__(
            promiseObjectId=promise_object_id,
            returnByValue=return_by_value,
            generatePreview=generate_preview
        )


class CallFunctionOnInput(InputModel):

    functionDeclaration: str
    objectId: Runtime.RemoteObjectId | None = None
    arguments: list[Runtime.CallArgument] | None = None
    silent: bool | None = None
    returnByValue: bool | None = None
    generatePreview: bool | None = None  # experimental
    userGesture: bool | None = None
    awaitPromise: bool | None = None
    executionContextId: Runtime.ExecutionContextId | None = None
    objectGroup: str | None = None
    throwOnSideEffect: bool | None = None  # experimental
    uniqueContextId: str | None = None  # experimental
    serializationOptions: Runtime.SerializationOptions | None = None  # experimental


class CallFunctionOnOutput(OutputModel):

    result: Runtime.RemoteObject
    exceptionDetails: Runtime.ExceptionDetails | None = None


class CallFunctionOn(CDPMethod[CallFunctionOnOutput]):
    """ Calls function with given declaration on the given object. Object group of the result is
    inherited from the target object. """

    INPUT_VALIDATOR = CallFunctionOnInput
    OUTPUT_VALIDATOR = CallFunctionOnOutput

    def __init__(
        self,
        *,
        function_declaration: str,
        object_id: Runtime.RemoteObjectId | None = None,
        arguments: list[Runtime.CallArgument] | None = None,
        silent: bool | None = None,
        return_by_value: bool | None = None,
        generate_preview: bool | None = None,
        user_gesture: bool | None = None,
        await_promise: bool | None = None,
        execution_context_id: Runtime.ExecutionContextId | None = None,
        object_group: str | None = None,
        throw_on_side_effect: bool | None = None,
        unique_context_id: str | None = None,
        serialization_options: Runtime.SerializationOptions | None = None
    ):
        super().__init__(
            functionDeclaration=function_declaration,
            objectId=object_id,
            arguments=arguments,
            silent=silent,
            returnByValue=return_by_value,
            generatePreview=generate_preview,
            userGesture=user_gesture,
            awaitPromise=await_promise,
            executionContextId=execution_context_id,
            objectGroup=object_group,
            throwOnSideEffect=throw_on_side_effect,
            uniqueContextId=unique_context_id,
            serializationOptions=serialization_options
        )


class CompileScriptInput(InputModel):

    expression: str
    sourceURL: str
    persistScript: bool
    executionContextId: Runtime.ExecutionContextId | None = None


class CompileScriptOutput(OutputModel):

    scriptId: Runtime.ScriptId | None = None
    exceptionDetails: Runtime.ExceptionDetails | None = None


class CompileScript(CDPMethod[CompileScriptOutput]):
    """ Compiles expression. """

    INPUT_VALIDATOR = CompileScriptInput
    OUTPUT_VALIDATOR = CompileScriptOutput

    def __init__(
        self,
        *,
        expression: str,
        source_url: str,
        persist_script: bool,
        execution_context_id: Runtime.ExecutionContextId | None = None
    ):
        super().__init__(
            expression=expression,
            sourceURL=source_url,
            persistScript=persist_script,
            executionContextId=execution_context_id
        )


class Disable(CDPMethod[None]):
    """ Disables reporting of execution contexts creation. """

    INPUT_VALIDATOR = None
    OUTPUT_VALIDATOR = None


class DiscardConsoleEntries(CDPMethod[None]):
    """ Discards collected exceptions and console API calls. """

    INPUT_VALIDATOR = None
    OUTPUT_VALIDATOR = None


class Enable(CDPMethod[None]):
    """ Enables reporting of execution contexts creation by means of `executionContextCreated` event.
    When the reporting gets enabled the event will be sent immediately for each existing execution
    context. """

    INPUT_VALIDATOR = None
    OUTPUT_VALIDATOR = None


class EvaluateInput(InputModel):

    expression: str
    objectGroup: str | None = None
    includeCommandLineAPI: bool | None = None
    silent: bool | None = None
    contextId: Runtime.ExecutionContextId | None = None
    returnByValue: bool | None = None
    generatePreview: bool | None = None  # experimental
    userGesture: bool | None = None
    awaitPromise: bool | None = None
    throwOnSideEffect: bool | None = None  # experimental
    timeout: Runtime.TimeDelta | None = None  # experimental
    disableBreaks: bool | None = None  # experimental
    replMode: bool | None = None  # experimental
    allowUnsafeEvalBlockedByCSP: bool | None = None  # experimental
    uniqueContextId: str | None = None  # experimental
    serializationOptions: Runtime.SerializationOptions | None = None  # experimental


class EvaluateOutput(OutputModel):

    result: Runtime.RemoteObject
    exceptionDetails: Runtime.ExceptionDetails | None = None


class Evaluate(CDPMethod[EvaluateOutput]):
    """ Evaluates expression on global object. """

    INPUT_VALIDATOR = EvaluateInput
    OUTPUT_VALIDATOR = EvaluateOutput

    def __init__(
        self,
        *,
        expression: str,
        object_group: str | None = None,
        include_command_line_api: bool | None = None,
        silent: bool | None = None,
        context_id: Runtime.ExecutionContextId | None = None,
        return_by_value: bool | None = None,
        generate_preview: bool | None = None,
        user_gesture: bool | None = None,
        await_promise: bool | None = None,
        throw_on_side_effect: bool | None = None,
        timeout: Runtime.TimeDelta | None = None,
        disable_breaks: bool | None = None,
        repl_mode: bool | None = None,
        allow_unsafe_eval_blocked_by_csp: bool | None = None,
        unique_context_id: str | None = None,
        serialization_options: Runtime.SerializationOptions | None = None
    ):
        super().__init__(
            expression=expression,
            objectGroup=object_group,
            includeCommandLineAPI=include_command_line_api,
            silent=silent,
            contextId=context_id,
            returnByValue=return_by_value,
            generatePreview=generate_preview,
            userGesture=user_gesture,
            awaitPromise=await_promise,
            throwOnSideEffect=throw_on_side_effect,
            timeout=timeout,
            disableBreaks=disable_breaks,
            replMode=repl_mode,
            allowUnsafeEvalBlockedByCSP=allow_unsafe_eval_blocked_by_csp,
            uniqueContextId=unique_context_id,
            serializationOptions=serialization_options
        )


class GetIsolateIdOutput(OutputModel):

    id: str


class GetIsolateId(CDPMethod[GetIsolateIdOutput]):  # experimental
    """ Returns the isolate id. """

    INPUT_VALIDATOR = None
    OUTPUT_VALIDATOR = GetIsolateIdOutput


class GetHeapUsageOutput(OutputModel):

    usedSize: float
    totalSize: float
    embedderHeapUsedSize: float
    backingStorageSize: float


class GetHeapUsage(CDPMethod[GetHeapUsageOutput]):  # experimental
    """ Returns the JavaScript heap usage.
    It is the total usage of the corresponding isolate not scoped to a particular Runtime. """

    INPUT_VALIDATOR = None
    OUTPUT_VALIDATOR = GetHeapUsageOutput


class GetPropertiesInput(InputModel):

    objectId: Runtime.RemoteObjectId
    ownProperties: bool | None = None
    accessorPropertiesOnly: bool | None = None  # experimental
    generatePreview: bool | None = None  # experimental
    nonIndexedPropertiesOnly: bool | None = None  # experimental


class GetPropertiesOutput(OutputModel):

    result: list[Runtime.PropertyDescriptor]
    internalProperties: list[Runtime.InternalPropertyDescriptor] | None = None
    privateProperties: list[Runtime.PrivatePropertyDescriptor] | None = None  # experimental
    exceptionDetails: Runtime.ExceptionDetails | None = None


class GetProperties(CDPMethod[GetPropertiesOutput]):
    """ Returns properties of a given object. Object group of the result is inherited from the target
    object. """

    INPUT_VALIDATOR = GetPropertiesInput
    OUTPUT_VALIDATOR = GetPropertiesOutput

    def __init__(
        self,
        *,
        object_id: Runtime.RemoteObjectId,
        own_properties: bool | None = None,
        accessor_properties_only: bool | None = None,
        generate_preview: bool | None = None,
        non_indexed_properties_only: bool | None = None
    ):
        super().__init__(
            objectId=object_id,
            ownProperties=own_properties,
            accessorPropertiesOnly=accessor_properties_only,
            generatePreview=generate_preview,
            nonIndexedPropertiesOnly=non_indexed_properties_only
        )


class GlobalLexicalScopeNamesInput(InputModel):

    executionContextId: Runtime.ExecutionContextId | None = None


class GlobalLexicalScopeNamesOutput(OutputModel):

    names: list[str]


class GlobalLexicalScopeNames(CDPMethod[GlobalLexicalScopeNamesOutput]):
    """ Returns all let, const and class variables from global scope. """

    INPUT_VALIDATOR = GlobalLexicalScopeNamesInput
    OUTPUT_VALIDATOR = GlobalLexicalScopeNamesOutput

    def __init__(
        self,
        *,
        execution_context_id: Runtime.ExecutionContextId | None = None
    ):
        super().__init__(
            executionContextId=execution_context_id
        )


class QueryObjectsInput(InputModel):

    prototypeObjectId: Runtime.RemoteObjectId
    objectGroup: str | None = None


class QueryObjectsOutput(OutputModel):

    objects: Runtime.RemoteObject


class QueryObjects(CDPMethod[QueryObjectsOutput]):

    INPUT_VALIDATOR = QueryObjectsInput
    OUTPUT_VALIDATOR = QueryObjectsOutput

    def __init__(
        self,
        *,
        prototype_object_id: Runtime.RemoteObjectId,
        object_group: str | None = None
    ):
        super().__init__(
            prototypeObjectId=prototype_object_id,
            objectGroup=object_group
        )


class ReleaseObjectInput(InputModel):

    objectId: Runtime.RemoteObjectId


class ReleaseObject(CDPMethod[None]):
    """ Releases remote object with given id. """

    INPUT_VALIDATOR = ReleaseObjectInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        object_id: Runtime.RemoteObjectId
    ):
        super().__init__(
            objectId=object_id
        )


class ReleaseObjectGroupInput(InputModel):

    objectGroup: str


class ReleaseObjectGroup(CDPMethod[None]):
    """ Releases all remote objects that belong to a given group. """

    INPUT_VALIDATOR = ReleaseObjectGroupInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        object_group: str
    ):
        super().__init__(
            objectGroup=object_group
        )


class RunIfWaitingForDebugger(CDPMethod[None]):
    """ Tells inspected instance to run if it was waiting for debugger to attach. """

    INPUT_VALIDATOR = None
    OUTPUT_VALIDATOR = None


class RunScriptInput(InputModel):

    scriptId: Runtime.ScriptId
    executionContextId: Runtime.ExecutionContextId | None = None
    objectGroup: str | None = None
    silent: bool | None = None
    includeCommandLineAPI: bool | None = None
    returnByValue: bool | None = None
    generatePreview: bool | None = None
    awaitPromise: bool | None = None


class RunScriptOutput(OutputModel):

    result: Runtime.RemoteObject
    exceptionDetails: Runtime.ExceptionDetails | None = None


class RunScript(CDPMethod[RunScriptOutput]):
    """ Runs script with given id in a given context. """

    INPUT_VALIDATOR = RunScriptInput
    OUTPUT_VALIDATOR = RunScriptOutput

    def __init__(
        self,
        *,
        script_id: Runtime.ScriptId,
        execution_context_id: Runtime.ExecutionContextId | None = None,
        object_group: str | None = None,
        silent: bool | None = None,
        include_command_line_api: bool | None = None,
        return_by_value: bool | None = None,
        generate_preview: bool | None = None,
        await_promise: bool | None = None
    ):
        super().__init__(
            scriptId=script_id,
            executionContextId=execution_context_id,
            objectGroup=object_group,
            silent=silent,
            includeCommandLineAPI=include_command_line_api,
            returnByValue=return_by_value,
            generatePreview=generate_preview,
            awaitPromise=await_promise
        )


class SetAsyncCallStackDepthInput(InputModel):

    maxDepth: int


class SetAsyncCallStackDepth(CDPMethod[None]):
    """ Enables or disables async call stacks tracking. """

    INPUT_VALIDATOR = SetAsyncCallStackDepthInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        max_depth: int
    ):
        super().__init__(
            maxDepth=max_depth
        )


class SetCustomObjectFormatterEnabledInput(InputModel):

    enabled: bool


class SetCustomObjectFormatterEnabled(CDPMethod[None]):  # experimental

    INPUT_VALIDATOR = SetCustomObjectFormatterEnabledInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        enabled: bool
    ):
        super().__init__(
            enabled=enabled
        )


class SetMaxCallStackSizeToCaptureInput(InputModel):

    size: int


class SetMaxCallStackSizeToCapture(CDPMethod[None]):  # experimental

    INPUT_VALIDATOR = SetMaxCallStackSizeToCaptureInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        size: int
    ):
        super().__init__(
            size=size
        )


class TerminateExecution(CDPMethod[None]):  # experimental
    """ Terminate current or next JavaScript execution.
    Will cancel the termination when the outer-most script execution ends. """

    INPUT_VALIDATOR = None
    OUTPUT_VALIDATOR = None


class AddBindingInput(InputModel):

    name: str
    executionContextId: Runtime.ExecutionContextId | None = None  # experimental deprecated
    executionContextName: str | None = None


class AddBinding(CDPMethod[None]):
    """ If executionContextId is empty, adds binding with the given name on the
    global objects of all inspected contexts, including those created later,
    bindings survive reloads.
    Binding function takes exactly one argument, this argument should be string,
    in case of any other input, function throws an exception.
    Each binding function call produces Runtime.bindingCalled notification. """

    INPUT_VALIDATOR = AddBindingInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        name: str,
        execution_context_id: Runtime.ExecutionContextId | None = None,
        execution_context_name: str | None = None
    ):
        super().__init__(
            name=name,
            executionContextId=execution_context_id,
            executionContextName=execution_context_name
        )


class RemoveBindingInput(InputModel):

    name: str


class RemoveBinding(CDPMethod[None]):
    """ This method does not remove binding function from global object but
    unsubscribes current runtime agent from Runtime.bindingCalled notifications. """

    INPUT_VALIDATOR = RemoveBindingInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        name: str
    ):
        super().__init__(
            name=name
        )


class GetExceptionDetailsInput(InputModel):

    errorObjectId: Runtime.RemoteObjectId


class GetExceptionDetailsOutput(OutputModel):

    exceptionDetails: Runtime.ExceptionDetails | None = None


class GetExceptionDetails(CDPMethod[GetExceptionDetailsOutput]):  # experimental
    """ This method tries to lookup and populate exception details for a
    JavaScript Error object.
    Note that the stackTrace portion of the resulting exceptionDetails will
    only be populated if the Runtime domain was enabled at the time when the
    Error was thrown. """

    INPUT_VALIDATOR = GetExceptionDetailsInput
    OUTPUT_VALIDATOR = GetExceptionDetailsOutput

    def __init__(
        self,
        *,
        error_object_id: Runtime.RemoteObjectId
    ):
        super().__init__(
            errorObjectId=error_object_id
        )
