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

from __future__ import annotations
from .address import Address, AddressTypedDict
from .organization_vat_regulation import OrganizationVatRegulation
from .url import URL, URLTypedDict
from enum import Enum
from mollie import models, utils
from mollie.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
import pydantic
from pydantic import field_serializer, model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class EntityOrganizationLocale(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The preferred locale of the merchant, as set in their Mollie dashboard."""

    EN_US = "en_US"
    EN_GB = "en_GB"
    NL_NL = "nl_NL"
    NL_BE = "nl_BE"
    DE_DE = "de_DE"
    DE_AT = "de_AT"
    DE_CH = "de_CH"
    FR_FR = "fr_FR"
    FR_BE = "fr_BE"
    ES_ES = "es_ES"
    CA_ES = "ca_ES"
    PT_PT = "pt_PT"
    IT_IT = "it_IT"
    NB_NO = "nb_NO"
    SV_SE = "sv_SE"
    FI_FI = "fi_FI"
    DA_DK = "da_DK"
    IS_IS = "is_IS"
    HU_HU = "hu_HU"
    PL_PL = "pl_PL"
    LV_LV = "lv_LV"
    LT_LT = "lt_LT"
    NULL = "null"


class EntityOrganizationLinksTypedDict(TypedDict):
    r"""An object with several relevant URLs. Every URL object will contain an `href` and a `type` field."""

    self_: NotRequired[URLTypedDict]
    r"""In v2 endpoints, URLs are commonly represented as objects with an `href` and `type` field."""
    dashboard: NotRequired[URLTypedDict]
    r"""In v2 endpoints, URLs are commonly represented as objects with an `href` and `type` field."""
    documentation: NotRequired[URLTypedDict]
    r"""In v2 endpoints, URLs are commonly represented as objects with an `href` and `type` field."""


class EntityOrganizationLinks(BaseModel):
    r"""An object with several relevant URLs. Every URL object will contain an `href` and a `type` field."""

    self_: Annotated[Optional[URL], pydantic.Field(alias="self")] = None
    r"""In v2 endpoints, URLs are commonly represented as objects with an `href` and `type` field."""

    dashboard: Optional[URL] = None
    r"""In v2 endpoints, URLs are commonly represented as objects with an `href` and `type` field."""

    documentation: Optional[URL] = None
    r"""In v2 endpoints, URLs are commonly represented as objects with an `href` and `type` field."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["self", "dashboard", "documentation"])
        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))

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

        return m


class EntityOrganizationTypedDict(TypedDict):
    resource: str
    r"""Indicates the response contains an organization object. Will always contain the string `organization` for this
    resource type.
    """
    id: str
    name: str
    r"""The name of the organization."""
    email: str
    r"""The email address associated with the organization."""
    locale: Nullable[EntityOrganizationLocale]
    r"""The preferred locale of the merchant, as set in their Mollie dashboard."""
    address: AddressTypedDict
    registration_number: str
    r"""The registration number of the organization at their local chamber of commerce."""
    links: EntityOrganizationLinksTypedDict
    r"""An object with several relevant URLs. Every URL object will contain an `href` and a `type` field."""
    vat_number: NotRequired[Nullable[str]]
    r"""The VAT number of the organization, if based in the European Union or in The United Kingdom. VAT numbers are
    verified against the international registry *VIES*.

    The field is not present for merchants residing in other countries.
    """
    vat_regulation: NotRequired[Nullable[OrganizationVatRegulation]]
    r"""Mollie applies Dutch VAT for merchants based in The Netherlands, British VAT for merchants based in The United
    Kingdom, and shifted VAT for merchants in the European Union.

    The field is not present for merchants residing in other countries.
    """


class EntityOrganization(BaseModel):
    resource: str
    r"""Indicates the response contains an organization object. Will always contain the string `organization` for this
    resource type.
    """

    id: str

    name: str
    r"""The name of the organization."""

    email: str
    r"""The email address associated with the organization."""

    locale: Nullable[EntityOrganizationLocale]
    r"""The preferred locale of the merchant, as set in their Mollie dashboard."""

    address: Address

    registration_number: Annotated[str, pydantic.Field(alias="registrationNumber")]
    r"""The registration number of the organization at their local chamber of commerce."""

    links: Annotated[EntityOrganizationLinks, pydantic.Field(alias="_links")]
    r"""An object with several relevant URLs. Every URL object will contain an `href` and a `type` field."""

    vat_number: Annotated[OptionalNullable[str], pydantic.Field(alias="vatNumber")] = (
        UNSET
    )
    r"""The VAT number of the organization, if based in the European Union or in The United Kingdom. VAT numbers are
    verified against the international registry *VIES*.

    The field is not present for merchants residing in other countries.
    """

    vat_regulation: Annotated[
        OptionalNullable[OrganizationVatRegulation],
        pydantic.Field(alias="vatRegulation"),
    ] = UNSET
    r"""Mollie applies Dutch VAT for merchants based in The Netherlands, British VAT for merchants based in The United
    Kingdom, and shifted VAT for merchants in the European Union.

    The field is not present for merchants residing in other countries.
    """

    @field_serializer("locale")
    def serialize_locale(self, value):
        if isinstance(value, str):
            try:
                return models.EntityOrganizationLocale(value)
            except ValueError:
                return value
        return value

    @field_serializer("vat_regulation")
    def serialize_vat_regulation(self, value):
        if isinstance(value, str):
            try:
                return models.OrganizationVatRegulation(value)
            except ValueError:
                return value
        return value

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["vatNumber", "vatRegulation"])
        nullable_fields = set(["locale", "vatNumber", "vatRegulation"])
        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


try:
    EntityOrganizationLinks.model_rebuild()
except NameError:
    pass
try:
    EntityOrganization.model_rebuild()
except NameError:
    pass
