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

from __future__ import annotations
from attio.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class PostScimV2UsersNameTypedDict(TypedDict):
    given_name: str
    family_name: str


class PostScimV2UsersName(BaseModel):
    given_name: Annotated[str, pydantic.Field(alias="givenName")]

    family_name: Annotated[str, pydantic.Field(alias="familyName")]


class PostScimV2UsersEmailTypedDict(TypedDict):
    value: str
    primary: bool
    type: NotRequired[str]


class PostScimV2UsersEmail(BaseModel):
    value: str

    primary: bool

    type: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["type"])
        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 PostScimV2UsersRoleTypedDict(TypedDict):
    value: str
    primary: bool


class PostScimV2UsersRole(BaseModel):
    value: str

    primary: bool


class PostScimV2UsersMetaTypedDict(TypedDict):
    resource_type: str
    created: str
    last_modified: str


class PostScimV2UsersMeta(BaseModel):
    resource_type: Annotated[str, pydantic.Field(alias="resourceType")]

    created: str

    last_modified: Annotated[str, pydantic.Field(alias="lastModified")]


class PostScimV2UsersResponseTypedDict(TypedDict):
    r"""Created"""

    schemas: List[str]
    id: str
    user_name: str
    name: PostScimV2UsersNameTypedDict
    emails: List[PostScimV2UsersEmailTypedDict]
    roles: List[PostScimV2UsersRoleTypedDict]
    active: bool
    meta: PostScimV2UsersMetaTypedDict
    profile_url: NotRequired[str]


class PostScimV2UsersResponse(BaseModel):
    r"""Created"""

    schemas: List[str]

    id: str

    user_name: Annotated[str, pydantic.Field(alias="userName")]

    name: PostScimV2UsersName

    emails: List[PostScimV2UsersEmail]

    roles: List[PostScimV2UsersRole]

    active: bool

    meta: PostScimV2UsersMeta

    profile_url: Annotated[Optional[str], pydantic.Field(alias="profileUrl")] = None

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


try:
    PostScimV2UsersName.model_rebuild()
except NameError:
    pass
try:
    PostScimV2UsersMeta.model_rebuild()
except NameError:
    pass
try:
    PostScimV2UsersResponse.model_rebuild()
except NameError:
    pass
