# coding: utf-8

"""
    RentCast API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.0
    Contact: support@rentcast.io
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt
from typing import Any, ClassVar, Dict, List, Optional, Union
from rentcast_client.models.rentcast_market_statistics200_response_sale_data_history202507_data_by_bedrooms_inner import RentcastMarketStatistics200ResponseSaleDataHistory202507DataByBedroomsInner
from rentcast_client.models.rentcast_market_statistics200_response_sale_data_history202507_data_by_property_type_inner import RentcastMarketStatistics200ResponseSaleDataHistory202507DataByPropertyTypeInner
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class RentcastMarketStatistics200ResponseSaleDataHistory202507(BaseModel):
    """
    RentcastMarketStatistics200ResponseSaleDataHistory202507
    """ # noqa: E501
    var_date: Optional[datetime] = Field(default=None, alias="date")
    average_price: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="averagePrice")
    median_price: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="medianPrice")
    min_price: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="minPrice")
    max_price: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="maxPrice")
    average_price_per_square_foot: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="averagePricePerSquareFoot")
    median_price_per_square_foot: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="medianPricePerSquareFoot")
    min_price_per_square_foot: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="minPricePerSquareFoot")
    max_price_per_square_foot: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="maxPricePerSquareFoot")
    average_square_footage: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="averageSquareFootage")
    median_square_footage: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="medianSquareFootage")
    min_square_footage: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="minSquareFootage")
    max_square_footage: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="maxSquareFootage")
    average_days_on_market: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="averageDaysOnMarket")
    median_days_on_market: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="medianDaysOnMarket")
    min_days_on_market: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="minDaysOnMarket")
    max_days_on_market: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="maxDaysOnMarket")
    new_listings: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="newListings")
    total_listings: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="totalListings")
    data_by_property_type: Optional[List[RentcastMarketStatistics200ResponseSaleDataHistory202507DataByPropertyTypeInner]] = Field(default=None, alias="dataByPropertyType")
    data_by_bedrooms: Optional[List[RentcastMarketStatistics200ResponseSaleDataHistory202507DataByBedroomsInner]] = Field(default=None, alias="dataByBedrooms")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["date", "averagePrice", "medianPrice", "minPrice", "maxPrice", "averagePricePerSquareFoot", "medianPricePerSquareFoot", "minPricePerSquareFoot", "maxPricePerSquareFoot", "averageSquareFootage", "medianSquareFootage", "minSquareFootage", "maxSquareFootage", "averageDaysOnMarket", "medianDaysOnMarket", "minDaysOnMarket", "maxDaysOnMarket", "newListings", "totalListings", "dataByPropertyType", "dataByBedrooms"]

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of RentcastMarketStatistics200ResponseSaleDataHistory202507 from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in data_by_property_type (list)
        _items = []
        if self.data_by_property_type:
            for _item_data_by_property_type in self.data_by_property_type:
                if _item_data_by_property_type:
                    _items.append(_item_data_by_property_type.to_dict())
            _dict['dataByPropertyType'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in data_by_bedrooms (list)
        _items = []
        if self.data_by_bedrooms:
            for _item_data_by_bedrooms in self.data_by_bedrooms:
                if _item_data_by_bedrooms:
                    _items.append(_item_data_by_bedrooms.to_dict())
            _dict['dataByBedrooms'] = _items
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of RentcastMarketStatistics200ResponseSaleDataHistory202507 from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "date": obj.get("date"),
            "averagePrice": obj.get("averagePrice") if obj.get("averagePrice") is not None else None,
            "medianPrice": obj.get("medianPrice") if obj.get("medianPrice") is not None else None,
            "minPrice": obj.get("minPrice") if obj.get("minPrice") is not None else None,
            "maxPrice": obj.get("maxPrice") if obj.get("maxPrice") is not None else None,
            "averagePricePerSquareFoot": obj.get("averagePricePerSquareFoot") if obj.get("averagePricePerSquareFoot") is not None else None,
            "medianPricePerSquareFoot": obj.get("medianPricePerSquareFoot") if obj.get("medianPricePerSquareFoot") is not None else None,
            "minPricePerSquareFoot": obj.get("minPricePerSquareFoot") if obj.get("minPricePerSquareFoot") is not None else None,
            "maxPricePerSquareFoot": obj.get("maxPricePerSquareFoot") if obj.get("maxPricePerSquareFoot") is not None else None,
            "averageSquareFootage": obj.get("averageSquareFootage") if obj.get("averageSquareFootage") is not None else None,
            "medianSquareFootage": obj.get("medianSquareFootage") if obj.get("medianSquareFootage") is not None else None,
            "minSquareFootage": obj.get("minSquareFootage") if obj.get("minSquareFootage") is not None else None,
            "maxSquareFootage": obj.get("maxSquareFootage") if obj.get("maxSquareFootage") is not None else None,
            "averageDaysOnMarket": obj.get("averageDaysOnMarket") if obj.get("averageDaysOnMarket") is not None else None,
            "medianDaysOnMarket": obj.get("medianDaysOnMarket") if obj.get("medianDaysOnMarket") is not None else None,
            "minDaysOnMarket": obj.get("minDaysOnMarket") if obj.get("minDaysOnMarket") is not None else None,
            "maxDaysOnMarket": obj.get("maxDaysOnMarket") if obj.get("maxDaysOnMarket") is not None else None,
            "newListings": obj.get("newListings") if obj.get("newListings") is not None else None,
            "totalListings": obj.get("totalListings") if obj.get("totalListings") is not None else None,
            "dataByPropertyType": [RentcastMarketStatistics200ResponseSaleDataHistory202507DataByPropertyTypeInner.from_dict(_item) for _item in obj["dataByPropertyType"]] if obj.get("dataByPropertyType") is not None else None,
            "dataByBedrooms": [RentcastMarketStatistics200ResponseSaleDataHistory202507DataByBedroomsInner.from_dict(_item) for _item in obj["dataByBedrooms"]] if obj.get("dataByBedrooms") is not None else None
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


