# coding: utf-8

"""
    Eazyrent products API

    EazyRent Products API ======================  Description ------------  The EazyRent Product API offers a comprehensive solution for managing rental and sale listings, including property details, media distribution, and data import capabilities. Designed for real estate professionals, this API allows users to create, update, and manage property listings efficiently while ensuring accurate data and broad market reach. With features to streamline listing distribution and import property data from other platforms, the Product API simplifies property management, helping agencies maintain up-to-date and comprehensive property portfolios.  Target Audience -----------------   * **Real Estate Agencies and Social Housing Providers:** Professionals who need a centralized system to manage property listings, including rental and sale offerings, media distribution, and data synchronization across various platforms.   * **Property Managers:** Organizations looking to efficiently organize and promote property listings, manage property details, and ensure accurate, consistent information across marketing channels.  Purpose ---------  The purpose of the EazyRent Product API is to enable streamlined property management within the EazyRent platform. By integrating this API, businesses can centralize their property data, automate distribution to marketing channels, and simplify the process of keeping listings updated. This provides agencies with a scalable, efficient way to manage property portfolios, ensuring quick, effective exposure to potential tenants and buyers.  How to use this API ---------------------  To get started with the EazyRent Product API, please refer to our comprehensive documentation for authentication details, endpoint descriptions, and integration guides. This resource will help you set up efficient property management workflows, from data import to listing updates and distribution, all accessible within your existing systems.

    The version of the OpenAPI document: 1
    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 date
from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from eazyrent.products.v1.models.room_specification import RoomSpecification
from typing import Optional, Set
from typing_extensions import Self


class BuildingInformation(BaseModel):
    """
    Represents general information about the building, including construction and renovation dates, energy grade, surface area, number of floors, and heating system.
    """  # noqa: E501

    construction_date: Optional[date] = None
    renovation_date: Optional[date] = None
    energy_grade: Optional[StrictStr] = None
    surface: Optional[Union[StrictFloat, StrictInt]] = None
    floor: Optional[StrictInt] = None
    floors: Optional[Annotated[int, Field(strict=True, ge=0)]] = None
    heating_system: Optional[StrictStr] = Field(
        default="other",
        description="The type of heating system used in the building. Defaults to 'other'.",
    )
    rooms: Optional[List[RoomSpecification]] = Field(
        default=None,
        description="A list of specifications for the rooms in the building. Each entry represents a different room. The list is empty if no rooms are specified.",
    )
    __properties: ClassVar[List[str]] = [
        "construction_date",
        "renovation_date",
        "energy_grade",
        "surface",
        "floor",
        "floors",
        "heating_system",
        "rooms",
    ]

    model_config = ConfigDict(
        populate_by_name=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"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of BuildingInformation 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.
        """
        excluded_fields: Set[str] = set([])

        _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 rooms (list)
        _items = []
        if self.rooms:
            for _item_rooms in self.rooms:
                if _item_rooms:
                    _items.append(_item_rooms.to_dict())
            _dict["rooms"] = _items
        # set to None if construction_date (nullable) is None
        # and model_fields_set contains the field
        if (
            self.construction_date is None
            and "construction_date" in self.model_fields_set
        ):
            _dict["construction_date"] = None

        # set to None if renovation_date (nullable) is None
        # and model_fields_set contains the field
        if self.renovation_date is None and "renovation_date" in self.model_fields_set:
            _dict["renovation_date"] = None

        # set to None if energy_grade (nullable) is None
        # and model_fields_set contains the field
        if self.energy_grade is None and "energy_grade" in self.model_fields_set:
            _dict["energy_grade"] = None

        # set to None if surface (nullable) is None
        # and model_fields_set contains the field
        if self.surface is None and "surface" in self.model_fields_set:
            _dict["surface"] = None

        # set to None if floor (nullable) is None
        # and model_fields_set contains the field
        if self.floor is None and "floor" in self.model_fields_set:
            _dict["floor"] = None

        # set to None if floors (nullable) is None
        # and model_fields_set contains the field
        if self.floors is None and "floors" in self.model_fields_set:
            _dict["floors"] = None

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "construction_date": obj.get("construction_date"),
                "renovation_date": obj.get("renovation_date"),
                "energy_grade": obj.get("energy_grade"),
                "surface": obj.get("surface"),
                "floor": obj.get("floor"),
                "floors": obj.get("floors"),
                "heating_system": obj.get("heating_system")
                if obj.get("heating_system") is not None
                else "other",
                "rooms": [RoomSpecification.from_dict(_item) for _item in obj["rooms"]]
                if obj.get("rooms") is not None
                else None,
            }
        )
        return _obj
