"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: 9927546f2487

from __future__ import annotations
from .connectioncredentials import ConnectionCredentials, ConnectionCredentialsTypedDict
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing_extensions import NotRequired, TypedDict


class CredentialsCreateOrUpdateTypedDict(TypedDict):
    r"""Request to create or update non-OAuth2 credentials for a connector."""

    name: str
    r"""Name of the credentials. Use this name to access or modify your credentials."""
    is_default: NotRequired[Nullable[bool]]
    r"""Controls whether this credential is the default for its auth method. On creation: if no credential exists yet for this auth method, the credential is automatically set as default when is_default is true or omitted; setting is_default to false is rejected because a default must exist. If other credentials already exist, setting is_default to true promotes this credential (demoting the previous default); false or omitted creates it as non-default. On update: true promotes this credential, false is rejected if it is currently the default (promote another credential first), omitted leaves the default status unchanged."""
    credentials: NotRequired[Nullable[ConnectionCredentialsTypedDict]]
    r"""The credential data (headers, bearer_token)."""


class CredentialsCreateOrUpdate(BaseModel):
    r"""Request to create or update non-OAuth2 credentials for a connector."""

    name: str
    r"""Name of the credentials. Use this name to access or modify your credentials."""

    is_default: OptionalNullable[bool] = UNSET
    r"""Controls whether this credential is the default for its auth method. On creation: if no credential exists yet for this auth method, the credential is automatically set as default when is_default is true or omitted; setting is_default to false is rejected because a default must exist. If other credentials already exist, setting is_default to true promotes this credential (demoting the previous default); false or omitted creates it as non-default. On update: true promotes this credential, false is rejected if it is currently the default (promote another credential first), omitted leaves the default status unchanged."""

    credentials: OptionalNullable[ConnectionCredentials] = UNSET
    r"""The credential data (headers, bearer_token)."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["is_default", "credentials"])
        nullable_fields = set(["is_default", "credentials"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m
