# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# pyformat: disable

"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from ..sdkconfiguration import SDKConfiguration
from abc import ABC, abstractmethod
import httpx
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union


class ResponseContext:
    mode: Literal["parsed", "raw", "streaming"]
    execution: Literal["sync", "async"]

    def __init__(
        self,
        mode: Literal["parsed", "raw", "streaming"] = "parsed",
        execution: Literal["sync", "async"] = "sync",
    ):
        self.mode = mode
        self.execution = execution


class HookContext:
    config: SDKConfiguration
    base_url: str
    operation_id: str
    oauth2_scopes: Optional[List[str]] = None
    security_source: Optional[Union[Any, Callable[[], Any]]] = None
    tags: Optional[List[str]] = None
    extensions: Optional[Dict[str, Any]] = None
    response: ResponseContext

    def __init__(
        self,
        config: SDKConfiguration,
        base_url: str,
        operation_id: str,
        oauth2_scopes: Optional[List[str]],
        security_source: Optional[Union[Any, Callable[[], Any]]],
        tags: Optional[List[str]],
        extensions: Optional[Dict[str, Any]],
        response: ResponseContext,
    ):
        self.config = config
        self.base_url = base_url
        self.operation_id = operation_id
        self.oauth2_scopes = oauth2_scopes
        self.security_source = security_source
        self.tags = tags
        self.extensions = extensions
        self.response = response


class BeforeRequestContext(HookContext):
    def __init__(self, hook_ctx: HookContext):
        super().__init__(
            hook_ctx.config,
            hook_ctx.base_url,
            hook_ctx.operation_id,
            hook_ctx.oauth2_scopes,
            hook_ctx.security_source,
            hook_ctx.tags,
            hook_ctx.extensions,
            response=hook_ctx.response,
        )


class AfterSuccessContext(HookContext):
    def __init__(self, hook_ctx: HookContext):
        super().__init__(
            hook_ctx.config,
            hook_ctx.base_url,
            hook_ctx.operation_id,
            hook_ctx.oauth2_scopes,
            hook_ctx.security_source,
            hook_ctx.tags,
            hook_ctx.extensions,
            response=hook_ctx.response,
        )


class AfterErrorContext(HookContext):
    def __init__(self, hook_ctx: HookContext):
        super().__init__(
            hook_ctx.config,
            hook_ctx.base_url,
            hook_ctx.operation_id,
            hook_ctx.oauth2_scopes,
            hook_ctx.security_source,
            hook_ctx.tags,
            hook_ctx.extensions,
            response=hook_ctx.response,
        )


class AfterParseErrorContext(HookContext):
    """Context for `AfterParseErrorHook`. Triggers when response parsing raises
    an exception while decoding the body.
    """

    def __init__(self, hook_ctx: HookContext):
        super().__init__(
            hook_ctx.config,
            hook_ctx.base_url,
            hook_ctx.operation_id,
            hook_ctx.oauth2_scopes,
            hook_ctx.security_source,
            hook_ctx.tags,
            hook_ctx.extensions,
            response=hook_ctx.response,
        )


class SDKInitHook(ABC):
    @abstractmethod
    def sdk_init(self, config: SDKConfiguration) -> SDKConfiguration:
        pass


class BeforeRequestHook(ABC):
    @abstractmethod
    def before_request(
        self, hook_ctx: BeforeRequestContext, request: httpx.Request
    ) -> Union[httpx.Request, Exception]:
        pass


class AfterSuccessHook(ABC):
    @abstractmethod
    def after_success(
        self, hook_ctx: AfterSuccessContext, response: httpx.Response
    ) -> Union[httpx.Response, Exception]:
        pass


class AfterErrorHook(ABC):
    @abstractmethod
    def after_error(
        self,
        hook_ctx: AfterErrorContext,
        response: Optional[httpx.Response],
        error: Optional[Exception],
    ) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
        pass


class AfterParseErrorHook(ABC):
    @abstractmethod
    def after_parse_error(
        self,
        hook_ctx: AfterParseErrorContext,
        response: httpx.Response,
        error: Exception,
    ) -> Exception:
        pass


class Hooks(ABC):
    @abstractmethod
    def register_sdk_init_hook(self, hook: SDKInitHook):
        pass

    @abstractmethod
    def register_before_request_hook(self, hook: BeforeRequestHook):
        pass

    @abstractmethod
    def register_after_success_hook(self, hook: AfterSuccessHook):
        pass

    @abstractmethod
    def register_after_error_hook(self, hook: AfterErrorHook):
        pass

    @abstractmethod
    def register_after_parse_error_hook(self, hook: AfterParseErrorHook):
        pass
