# coding: utf-8

"""
    Skyledge API

    Sky Ledge is an operational insights platform that gives you the visibility and control you need to minimise inefficiencies, oversight, theft, and ultimately, unnecessary costs associated with your operations.

    The version of the OpenAPI document: 1.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 importlib import import_module
from pydantic import BaseModel, ConfigDict, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from skyledge_sdk.models.crs import Crs
from typing import Optional, Set
from typing_extensions import Self

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from skyledge_sdk.models.feature import Feature
    from skyledge_sdk.models.feature_collection import FeatureCollection
    from skyledge_sdk.models.geometry_collection import GeometryCollection
    from skyledge_sdk.models.line_string import LineString
    from skyledge_sdk.models.multi_line_string import MultiLineString
    from skyledge_sdk.models.multi_point import MultiPoint
    from skyledge_sdk.models.multi_polygon import MultiPolygon
    from skyledge_sdk.models.point import Point
    from skyledge_sdk.models.polygon import Polygon

class GeoJsonObject(BaseModel):
    """
    GeoJsonObject
    """ # noqa: E501
    crs: Optional[Crs] = None
    bbox: Optional[List[Union[StrictFloat, StrictInt]]] = None
    type: StrictStr
    __properties: ClassVar[List[str]] = ["crs", "bbox", "type"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    # JSON field name that stores the object type
    __discriminator_property_name: ClassVar[str] = 'type'

    # discriminator mappings
    __discriminator_value_class_map: ClassVar[Dict[str, str]] = {
        'Feature': 'Feature','FeatureCollection': 'FeatureCollection','GeometryCollection': 'GeometryCollection','LineString': 'LineString','MultiLineString': 'MultiLineString','MultiPoint': 'MultiPoint','MultiPolygon': 'MultiPolygon','Point': 'Point','Polygon': 'Polygon'
    }

    @classmethod
    def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]:
        """Returns the discriminator value (object type) of the data"""
        discriminator_value = obj[cls.__discriminator_property_name]
        if discriminator_value:
            return cls.__discriminator_value_class_map.get(discriminator_value)
        else:
            return None

    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[Union[Feature, FeatureCollection, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon]]:
        """Create an instance of GeoJsonObject 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 crs
        if self.crs:
            _dict['crs'] = self.crs.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[Feature, FeatureCollection, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon]]:
        """Create an instance of GeoJsonObject from a dict"""
        # look up the object type based on discriminator mapping
        object_type = cls.get_discriminator_value(obj)
        if object_type ==  'Feature':
            return import_module("skyledge_sdk.models.feature").Feature.from_dict(obj)
        if object_type ==  'FeatureCollection':
            return import_module("skyledge_sdk.models.feature_collection").FeatureCollection.from_dict(obj)
        if object_type ==  'GeometryCollection':
            return import_module("skyledge_sdk.models.geometry_collection").GeometryCollection.from_dict(obj)
        if object_type ==  'LineString':
            return import_module("skyledge_sdk.models.line_string").LineString.from_dict(obj)
        if object_type ==  'MultiLineString':
            return import_module("skyledge_sdk.models.multi_line_string").MultiLineString.from_dict(obj)
        if object_type ==  'MultiPoint':
            return import_module("skyledge_sdk.models.multi_point").MultiPoint.from_dict(obj)
        if object_type ==  'MultiPolygon':
            return import_module("skyledge_sdk.models.multi_polygon").MultiPolygon.from_dict(obj)
        if object_type ==  'Point':
            return import_module("skyledge_sdk.models.point").Point.from_dict(obj)
        if object_type ==  'Polygon':
            return import_module("skyledge_sdk.models.polygon").Polygon.from_dict(obj)

        raise ValueError("GeoJsonObject failed to lookup discriminator value from " +
                            json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name +
                            ", mapping: " + json.dumps(cls.__discriminator_value_class_map))


