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

A domain for letting clients substitute browser's network layer with client code.
https://chromedevtools.github.io/devtools-protocol/tot/Fetch/

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

from cdpkit.protocol._types import (
    IO,
    Fetch,
    Network,
)
from cdpkit.protocol.base import CDPMethod, InputModel, OutputModel


class Disable(CDPMethod[None]):
    """ Disables the fetch domain. """

    INPUT_VALIDATOR = None
    OUTPUT_VALIDATOR = None


class EnableInput(InputModel):

    patterns: list[Fetch.RequestPattern] | None = None
    handleAuthRequests: bool | None = None


class Enable(CDPMethod[None]):
    """ Enables issuing of requestPaused events. A request will be paused until client
    calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth. """

    INPUT_VALIDATOR = EnableInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        patterns: list[Fetch.RequestPattern] | None = None,
        handle_auth_requests: bool | None = None
    ):
        super().__init__(
            patterns=patterns,
            handleAuthRequests=handle_auth_requests
        )


class FailRequestInput(InputModel):

    requestId: Fetch.RequestId
    errorReason: Network.ErrorReason


class FailRequest(CDPMethod[None]):
    """ Causes the request to fail with specified reason. """

    INPUT_VALIDATOR = FailRequestInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        request_id: Fetch.RequestId,
        error_reason: Network.ErrorReason
    ):
        super().__init__(
            requestId=request_id,
            errorReason=error_reason
        )


class FulfillRequestInput(InputModel):

    requestId: Fetch.RequestId
    responseCode: int
    responseHeaders: list[Fetch.HeaderEntry] | None = None
    binaryResponseHeaders: str | None = None
    body: str | None = None
    responsePhrase: str | None = None


class FulfillRequest(CDPMethod[None]):
    """ Provides response to the request. """

    INPUT_VALIDATOR = FulfillRequestInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        request_id: Fetch.RequestId,
        response_code: int,
        response_headers: list[Fetch.HeaderEntry] | None = None,
        binary_response_headers: str | None = None,
        body: str | None = None,
        response_phrase: str | None = None
    ):
        super().__init__(
            requestId=request_id,
            responseCode=response_code,
            responseHeaders=response_headers,
            binaryResponseHeaders=binary_response_headers,
            body=body,
            responsePhrase=response_phrase
        )


class ContinueRequestInput(InputModel):

    requestId: Fetch.RequestId
    url: str | None = None
    method: str | None = None
    postData: str | None = None
    headers: list[Fetch.HeaderEntry] | None = None
    interceptResponse: bool | None = None  # experimental


class ContinueRequest(CDPMethod[None]):
    """ Continues the request, optionally modifying some of its parameters. """

    INPUT_VALIDATOR = ContinueRequestInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        request_id: Fetch.RequestId,
        url: str | None = None,
        method: str | None = None,
        post_data: str | None = None,
        headers: list[Fetch.HeaderEntry] | None = None,
        intercept_response: bool | None = None
    ):
        super().__init__(
            requestId=request_id,
            url=url,
            method=method,
            postData=post_data,
            headers=headers,
            interceptResponse=intercept_response
        )


class ContinueWithAuthInput(InputModel):

    requestId: Fetch.RequestId
    authChallengeResponse: Fetch.AuthChallengeResponse


class ContinueWithAuth(CDPMethod[None]):
    """ Continues a request supplying authChallengeResponse following authRequired event. """

    INPUT_VALIDATOR = ContinueWithAuthInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        request_id: Fetch.RequestId,
        auth_challenge_response: Fetch.AuthChallengeResponse
    ):
        super().__init__(
            requestId=request_id,
            authChallengeResponse=auth_challenge_response
        )


class ContinueResponseInput(InputModel):

    requestId: Fetch.RequestId
    responseCode: int | None = None
    responsePhrase: str | None = None
    responseHeaders: list[Fetch.HeaderEntry] | None = None
    binaryResponseHeaders: str | None = None


class ContinueResponse(CDPMethod[None]):  # experimental
    """ Continues loading of the paused response, optionally modifying the
    response headers. If either responseCode or headers are modified, all of them
    must be present. """

    INPUT_VALIDATOR = ContinueResponseInput
    OUTPUT_VALIDATOR = None

    def __init__(
        self,
        *,
        request_id: Fetch.RequestId,
        response_code: int | None = None,
        response_phrase: str | None = None,
        response_headers: list[Fetch.HeaderEntry] | None = None,
        binary_response_headers: str | None = None
    ):
        super().__init__(
            requestId=request_id,
            responseCode=response_code,
            responsePhrase=response_phrase,
            responseHeaders=response_headers,
            binaryResponseHeaders=binary_response_headers
        )


class GetResponseBodyInput(InputModel):

    requestId: Fetch.RequestId


class GetResponseBodyOutput(OutputModel):

    body: str
    base64Encoded: bool


class GetResponseBody(CDPMethod[GetResponseBodyOutput]):
    """ Causes the body of the response to be received from the server and
    returned as a single string. May only be issued for a request that
    is paused in the Response stage and is mutually exclusive with
    takeResponseBodyForInterceptionAsStream. Calling other methods that
    affect the request or disabling fetch domain before body is received
    results in an undefined behavior.
    Note that the response body is not available for redirects. Requests
    paused in the _redirect received_ state may be differentiated by
    `responseCode` and presence of `location` response header, see
    comments to `requestPaused` for details. """

    INPUT_VALIDATOR = GetResponseBodyInput
    OUTPUT_VALIDATOR = GetResponseBodyOutput

    def __init__(
        self,
        *,
        request_id: Fetch.RequestId
    ):
        super().__init__(
            requestId=request_id
        )


class TakeResponseBodyAsStreamInput(InputModel):

    requestId: Fetch.RequestId


class TakeResponseBodyAsStreamOutput(OutputModel):

    stream: IO.StreamHandle


class TakeResponseBodyAsStream(CDPMethod[TakeResponseBodyAsStreamOutput]):
    """ Returns a handle to the stream representing the response body.
    The request must be paused in the HeadersReceived stage.
    Note that after this command the request can't be continued
    as is -- client either needs to cancel it or to provide the
    response body.
    The stream only supports sequential read, IO.read will fail if the position
    is specified.
    This method is mutually exclusive with getResponseBody.
    Calling other methods that affect the request or disabling fetch
    domain before body is received results in an undefined behavior. """

    INPUT_VALIDATOR = TakeResponseBodyAsStreamInput
    OUTPUT_VALIDATOR = TakeResponseBodyAsStreamOutput

    def __init__(
        self,
        *,
        request_id: Fetch.RequestId
    ):
        super().__init__(
            requestId=request_id
        )
