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

from __future__ import annotations
from moovio_sdk.models.components import (
    institutionssearchresponse as components_institutionssearchresponse,
)
from moovio_sdk.types import BaseModel, UNSET_SENTINEL
from moovio_sdk.utils import FieldMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class SearchInstitutionsRequestTypedDict(TypedDict):
    name: NotRequired[str]
    r"""Name of the financial institution. Either `name` or `routingNumber` is required."""
    routing_number: NotRequired[str]
    r"""Routing number for a financial institution. Either `routingNumber` or `name` is required."""
    limit: NotRequired[int]
    r"""Maximum results returned by a search."""


class SearchInstitutionsRequest(BaseModel):
    name: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=False)),
    ] = None
    r"""Name of the financial institution. Either `name` or `routingNumber` is required."""

    routing_number: Annotated[
        Optional[str],
        pydantic.Field(alias="routingNumber"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=False)),
    ] = None
    r"""Routing number for a financial institution. Either `routingNumber` or `name` is required."""

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=False)),
    ] = None
    r"""Maximum results returned by a search."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["name", "routingNumber", "limit"])
        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 SearchInstitutionsResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: components_institutionssearchresponse.InstitutionsSearchResponseTypedDict


class SearchInstitutionsResponse(BaseModel):
    headers: Dict[str, List[str]]

    result: components_institutionssearchresponse.InstitutionsSearchResponse
