# coding: utf-8

"""
    DUPR Backend APIs

    Internal RESTful APIs to access DUPR ratings, users and provide matches.

    The version of the OpenAPI document: v1.0.0
    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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from dupr_backend.models.address_component import AddressComponent
from dupr_backend.models.geometry import Geometry
from dupr_backend.models.plus_code import PlusCode
from typing import Optional, Set
from typing_extensions import Self

class GeocodingResult(BaseModel):
    """
    GeocodingResult
    """ # noqa: E501
    address_components: Optional[List[AddressComponent]] = Field(default=None, alias="addressComponents")
    formatted_address: Optional[StrictStr] = Field(default=None, alias="formattedAddress")
    postcode_localities: Optional[List[StrictStr]] = Field(default=None, alias="postcodeLocalities")
    geometry: Optional[Geometry] = None
    types: Optional[List[StrictStr]] = None
    partial_match: Optional[StrictBool] = Field(default=None, alias="partialMatch")
    place_id: Optional[StrictStr] = Field(default=None, alias="placeId")
    plus_code: Optional[PlusCode] = Field(default=None, alias="plusCode")
    __properties: ClassVar[List[str]] = ["addressComponents", "formattedAddress", "postcodeLocalities", "geometry", "types", "partialMatch", "placeId", "plusCode"]

    @field_validator('types')
    def types_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        for i in value:
            if i not in set(['street_address', 'street_number', 'floor', 'room', 'post_box', 'route', 'intersection', 'continent', 'political', 'country', 'administrative_area_level_1', 'administrative_area_level_2', 'administrative_area_level_3', 'administrative_area_level_4', 'administrative_area_level_5', 'colloquial_area', 'locality', 'ward', 'sublocality', 'sublocality_level_1', 'sublocality_level_2', 'sublocality_level_3', 'sublocality_level_4', 'sublocality_level_5', 'neighborhood', 'premise', 'subpremise', 'postal_code', 'postal_code_prefix', 'postal_code_suffix', 'plus_code', 'natural_feature', 'airport', 'university', 'park', 'museum', 'point_of_interest', 'establishment', 'bus_station', 'train_station', 'subway_station', 'transit_station', 'light_rail_station', 'church', 'primary_school', 'secondary_school', 'finance', 'post_office', 'place_of_worship', 'postal_town', 'synagogue', 'food', 'grocery_or_supermarket', 'store', 'drugstore', 'lawyer', 'health', 'insurance_agency', 'gas_station', 'car_dealer', 'car_repair', 'meal_takeaway', 'furniture_store', 'home_goods_store', 'shopping_mall', 'gym', 'accounting', 'moving_company', 'lodging', 'storage', 'casino', 'parking', 'stadium', 'travel_agency', 'night_club', 'beauty_salon', 'hair_care', 'spa', 'shoe_store', 'bakery', 'pharmacy', 'school', 'book_store', 'department_store', 'restaurant', 'real_estate_agency', 'bar', 'doctor', 'hospital', 'fire_station', 'supermarket', 'city_hall', 'local_government_office', 'atm', 'bank', 'library', 'car_wash', 'hardware_store', 'amusement_park', 'aquarium', 'art_gallery', 'bicycle_store', 'bowling_alley', 'cafe', 'campground', 'car_rental', 'cemetery', 'clothing_store', 'convenience_store', 'courthouse', 'dentist', 'electrician', 'electronics_store', 'embassy', 'florist', 'funeral_home', 'general_contractor', 'hindu_temple', 'jewelry_store', 'laundry', 'liquor_store', 'locksmith', 'meal_delivery', 'mosque', 'movie_rental', 'movie_theater', 'painter', 'pet_store', 'physiotherapist', 'plumber', 'police', 'roofing_contractor', 'rv_park', 'taxi_stand', 'veterinary_care', 'zoo', 'archipelago', 'tourist_attraction', 'town_square', 'unknown']):
                raise ValueError("each list item must be one of ('street_address', 'street_number', 'floor', 'room', 'post_box', 'route', 'intersection', 'continent', 'political', 'country', 'administrative_area_level_1', 'administrative_area_level_2', 'administrative_area_level_3', 'administrative_area_level_4', 'administrative_area_level_5', 'colloquial_area', 'locality', 'ward', 'sublocality', 'sublocality_level_1', 'sublocality_level_2', 'sublocality_level_3', 'sublocality_level_4', 'sublocality_level_5', 'neighborhood', 'premise', 'subpremise', 'postal_code', 'postal_code_prefix', 'postal_code_suffix', 'plus_code', 'natural_feature', 'airport', 'university', 'park', 'museum', 'point_of_interest', 'establishment', 'bus_station', 'train_station', 'subway_station', 'transit_station', 'light_rail_station', 'church', 'primary_school', 'secondary_school', 'finance', 'post_office', 'place_of_worship', 'postal_town', 'synagogue', 'food', 'grocery_or_supermarket', 'store', 'drugstore', 'lawyer', 'health', 'insurance_agency', 'gas_station', 'car_dealer', 'car_repair', 'meal_takeaway', 'furniture_store', 'home_goods_store', 'shopping_mall', 'gym', 'accounting', 'moving_company', 'lodging', 'storage', 'casino', 'parking', 'stadium', 'travel_agency', 'night_club', 'beauty_salon', 'hair_care', 'spa', 'shoe_store', 'bakery', 'pharmacy', 'school', 'book_store', 'department_store', 'restaurant', 'real_estate_agency', 'bar', 'doctor', 'hospital', 'fire_station', 'supermarket', 'city_hall', 'local_government_office', 'atm', 'bank', 'library', 'car_wash', 'hardware_store', 'amusement_park', 'aquarium', 'art_gallery', 'bicycle_store', 'bowling_alley', 'cafe', 'campground', 'car_rental', 'cemetery', 'clothing_store', 'convenience_store', 'courthouse', 'dentist', 'electrician', 'electronics_store', 'embassy', 'florist', 'funeral_home', 'general_contractor', 'hindu_temple', 'jewelry_store', 'laundry', 'liquor_store', 'locksmith', 'meal_delivery', 'mosque', 'movie_rental', 'movie_theater', 'painter', 'pet_store', 'physiotherapist', 'plumber', 'police', 'roofing_contractor', 'rv_park', 'taxi_stand', 'veterinary_care', 'zoo', 'archipelago', 'tourist_attraction', 'town_square', 'unknown')")
        return value

    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 GeocodingResult 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 address_components (list)
        _items = []
        if self.address_components:
            for _item_address_components in self.address_components:
                if _item_address_components:
                    _items.append(_item_address_components.to_dict())
            _dict['addressComponents'] = _items
        # override the default output from pydantic by calling `to_dict()` of geometry
        if self.geometry:
            _dict['geometry'] = self.geometry.to_dict()
        # override the default output from pydantic by calling `to_dict()` of plus_code
        if self.plus_code:
            _dict['plusCode'] = self.plus_code.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "addressComponents": [AddressComponent.from_dict(_item) for _item in obj["addressComponents"]] if obj.get("addressComponents") is not None else None,
            "formattedAddress": obj.get("formattedAddress"),
            "postcodeLocalities": obj.get("postcodeLocalities"),
            "geometry": Geometry.from_dict(obj["geometry"]) if obj.get("geometry") is not None else None,
            "types": obj.get("types"),
            "partialMatch": obj.get("partialMatch"),
            "placeId": obj.get("placeId"),
            "plusCode": PlusCode.from_dict(obj["plusCode"]) if obj.get("plusCode") is not None else None
        })
        return _obj


