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

from __future__ import annotations
from .capability_status import CapabilityStatus
from .capability_status_reason import CapabilityStatusReason
from .entity_capability_requirement import (
    EntityCapabilityRequirement,
    EntityCapabilityRequirementTypedDict,
)
from mollie import models
from mollie.types import BaseModel, Nullable, UNSET_SENTINEL
import pydantic
from pydantic import field_serializer, model_serializer
from typing import List
from typing_extensions import Annotated, TypedDict


class EntityCapabilityTypedDict(TypedDict):
    resource: str
    r"""Always the word `capability` for this resource type."""
    name: str
    r"""A unique name for this capability like `payments` / `settlements`."""
    status: CapabilityStatus
    status_reason: Nullable[CapabilityStatusReason]
    requirements: List[EntityCapabilityRequirementTypedDict]


class EntityCapability(BaseModel):
    resource: str
    r"""Always the word `capability` for this resource type."""

    name: str
    r"""A unique name for this capability like `payments` / `settlements`."""

    status: CapabilityStatus

    status_reason: Annotated[
        Nullable[CapabilityStatusReason], pydantic.Field(alias="statusReason")
    ]

    requirements: List[EntityCapabilityRequirement]

    @field_serializer("status")
    def serialize_status(self, value):
        if isinstance(value, str):
            try:
                return models.CapabilityStatus(value)
            except ValueError:
                return value
        return value

    @field_serializer("status_reason")
    def serialize_status_reason(self, value):
        if isinstance(value, str):
            try:
                return models.CapabilityStatusReason(value)
            except ValueError:
                return value
        return value

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        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:
                m[k] = val

        return m


try:
    EntityCapability.model_rebuild()
except NameError:
    pass
