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

from __future__ import annotations
from datetime import datetime
from enum import Enum
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict
from zillow_rapidapi_client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)


class PropertyType(str, Enum):
    SINGLE_FAMILY = "SINGLE_FAMILY"
    MULTI_FAMILY = "MULTI_FAMILY"
    CONDO = "CONDO"
    TOWNHOUSE = "TOWNHOUSE"
    APARTMENT = "APARTMENT"
    LAND = "LAND"


class ListingStatus(str, Enum):
    FOR_SALE = "FOR_SALE"
    PENDING = "PENDING"
    SOLD = "SOLD"


class ListingSubTypeTypedDict(TypedDict):
    is_fsba: NotRequired[bool]


class ListingSubType(BaseModel):
    is_fsba: Annotated[Optional[bool], pydantic.Field(alias="is_FSBA")] = None


class PropertyTypedDict(TypedDict):
    date_sold: NotRequired[Nullable[datetime]]
    property_type: NotRequired[PropertyType]
    lot_area_value: NotRequired[float]
    address: NotRequired[str]
    img_src: NotRequired[str]
    price: NotRequired[float]
    bedrooms: NotRequired[int]
    longitude: NotRequired[float]
    latitude: NotRequired[float]
    listing_status: NotRequired[ListingStatus]
    zpid: NotRequired[str]
    listing_sub_type: NotRequired[ListingSubTypeTypedDict]
    days_on_zillow: NotRequired[int]
    bathrooms: NotRequired[float]
    living_area: NotRequired[int]
    country: NotRequired[str]
    currency: NotRequired[str]
    lot_area_unit: NotRequired[str]
    has_image: NotRequired[bool]


class Property(BaseModel):
    date_sold: Annotated[
        OptionalNullable[datetime], pydantic.Field(alias="dateSold")
    ] = UNSET

    property_type: Annotated[
        Optional[PropertyType], pydantic.Field(alias="propertyType")
    ] = None

    lot_area_value: Annotated[Optional[float], pydantic.Field(alias="lotAreaValue")] = (
        None
    )

    address: Optional[str] = None

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

    price: Optional[float] = None

    bedrooms: Optional[int] = None

    longitude: Optional[float] = None

    latitude: Optional[float] = None

    listing_status: Annotated[
        Optional[ListingStatus], pydantic.Field(alias="listingStatus")
    ] = None

    zpid: Optional[str] = None

    listing_sub_type: Annotated[
        Optional[ListingSubType], pydantic.Field(alias="listingSubType")
    ] = None

    days_on_zillow: Annotated[Optional[int], pydantic.Field(alias="daysOnZillow")] = (
        None
    )

    bathrooms: Optional[float] = None

    living_area: Annotated[Optional[int], pydantic.Field(alias="livingArea")] = None

    country: Optional[str] = None

    currency: Optional[str] = None

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

    has_image: Annotated[Optional[bool], pydantic.Field(alias="hasImage")] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "dateSold",
            "propertyType",
            "lotAreaValue",
            "address",
            "imgSrc",
            "price",
            "bedrooms",
            "longitude",
            "latitude",
            "listingStatus",
            "zpid",
            "listingSubType",
            "daysOnZillow",
            "bathrooms",
            "livingArea",
            "country",
            "currency",
            "lotAreaUnit",
            "hasImage",
        ]
        nullable_fields = ["dateSold"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
