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

from __future__ import annotations
from pydantic import model_serializer
from typing import List
from typing_extensions import NotRequired, TypedDict
from unstructured_client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)


class OpenSearchConnectorConfigTypedDict(TypedDict):
    r"""OpenSearch connector configuration.

    OpenSearch is a fork of Elasticsearch with similar functionality.
    Supports two authentication methods:
    1. Basic auth: username + password
    2. AWS IAM auth: aws_access_key_id + aws_secret_access_key (+ optional aws_session_token)

    For AWS OpenSearch Service or OpenSearch Serverless, region and service type
    are auto-detected from the host URL.
    """

    hosts: List[str]
    r"""List of OpenSearch hosts to connect to"""
    index_name: str
    r"""Name of the OpenSearch index to read from or write to"""
    aws_access_key_id: NotRequired[Nullable[str]]
    r"""AWS access key ID for IAM authentication. When provided with aws_secret_access_key, IAM authentication is used instead of basic auth. Region and service type are auto-detected from the host URL."""
    aws_secret_access_key: NotRequired[Nullable[str]]
    r"""AWS secret access key for IAM authentication. Required when aws_access_key_id is provided."""
    aws_session_token: NotRequired[Nullable[str]]
    r"""AWS session token for temporary credentials (optional). Only used when aws_access_key_id and aws_secret_access_key are provided."""
    password: NotRequired[Nullable[str]]
    r"""Password for basic authentication"""
    use_ssl: NotRequired[Nullable[bool]]
    r"""Whether to use SSL for the connection"""
    username: NotRequired[Nullable[str]]
    r"""Username for basic authentication"""


class OpenSearchConnectorConfig(BaseModel):
    r"""OpenSearch connector configuration.

    OpenSearch is a fork of Elasticsearch with similar functionality.
    Supports two authentication methods:
    1. Basic auth: username + password
    2. AWS IAM auth: aws_access_key_id + aws_secret_access_key (+ optional aws_session_token)

    For AWS OpenSearch Service or OpenSearch Serverless, region and service type
    are auto-detected from the host URL.
    """

    hosts: List[str]
    r"""List of OpenSearch hosts to connect to"""

    index_name: str
    r"""Name of the OpenSearch index to read from or write to"""

    aws_access_key_id: OptionalNullable[str] = UNSET
    r"""AWS access key ID for IAM authentication. When provided with aws_secret_access_key, IAM authentication is used instead of basic auth. Region and service type are auto-detected from the host URL."""

    aws_secret_access_key: OptionalNullable[str] = UNSET
    r"""AWS secret access key for IAM authentication. Required when aws_access_key_id is provided."""

    aws_session_token: OptionalNullable[str] = UNSET
    r"""AWS session token for temporary credentials (optional). Only used when aws_access_key_id and aws_secret_access_key are provided."""

    password: OptionalNullable[str] = UNSET
    r"""Password for basic authentication"""

    use_ssl: OptionalNullable[bool] = UNSET
    r"""Whether to use SSL for the connection"""

    username: OptionalNullable[str] = UNSET
    r"""Username for basic authentication"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "aws_access_key_id",
            "aws_secret_access_key",
            "aws_session_token",
            "password",
            "use_ssl",
            "username",
        ]
        nullable_fields = [
            "aws_access_key_id",
            "aws_secret_access_key",
            "aws_session_token",
            "password",
            "use_ssl",
            "username",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
