# 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 json
import pprint
from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator
from typing import Any, List, Optional
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
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

GEOMETRYCOLLECTIONALLOFGEOMETRIES_ONE_OF_SCHEMAS = ["Feature", "FeatureCollection", "GeometryCollection", "LineString", "MultiLineString", "MultiPoint", "MultiPolygon", "Point", "Polygon"]

class GeometryCollectionAllOfGeometries(BaseModel):
    """
    GeometryCollectionAllOfGeometries
    """
    # data type: Feature
    oneof_schema_1_validator: Optional[Feature] = None
    # data type: FeatureCollection
    oneof_schema_2_validator: Optional[FeatureCollection] = None
    # data type: GeometryCollection
    oneof_schema_3_validator: Optional[GeometryCollection] = None
    # data type: LineString
    oneof_schema_4_validator: Optional[LineString] = None
    # data type: MultiLineString
    oneof_schema_5_validator: Optional[MultiLineString] = None
    # data type: MultiPoint
    oneof_schema_6_validator: Optional[MultiPoint] = None
    # data type: MultiPolygon
    oneof_schema_7_validator: Optional[MultiPolygon] = None
    # data type: Point
    oneof_schema_8_validator: Optional[Point] = None
    # data type: Polygon
    oneof_schema_9_validator: Optional[Polygon] = None
    actual_instance: Optional[Union[Feature, FeatureCollection, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon]] = None
    one_of_schemas: Set[str] = { "Feature", "FeatureCollection", "GeometryCollection", "LineString", "MultiLineString", "MultiPoint", "MultiPolygon", "Point", "Polygon" }

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


    def __init__(self, *args, **kwargs) -> None:
        if args:
            if len(args) > 1:
                raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`")
            if kwargs:
                raise ValueError("If a position argument is used, keyword arguments cannot be used.")
            super().__init__(actual_instance=args[0])
        else:
            super().__init__(**kwargs)

    @field_validator('actual_instance')
    def actual_instance_must_validate_oneof(cls, v):
        instance = GeometryCollectionAllOfGeometries.model_construct()
        error_messages = []
        match = 0
        # validate data type: Feature
        if not isinstance(v, Feature):
            error_messages.append(f"Error! Input type `{type(v)}` is not `Feature`")
        else:
            match += 1
        # validate data type: FeatureCollection
        if not isinstance(v, FeatureCollection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `FeatureCollection`")
        else:
            match += 1
        # validate data type: GeometryCollection
        if not isinstance(v, GeometryCollection):
            error_messages.append(f"Error! Input type `{type(v)}` is not `GeometryCollection`")
        else:
            match += 1
        # validate data type: LineString
        if not isinstance(v, LineString):
            error_messages.append(f"Error! Input type `{type(v)}` is not `LineString`")
        else:
            match += 1
        # validate data type: MultiLineString
        if not isinstance(v, MultiLineString):
            error_messages.append(f"Error! Input type `{type(v)}` is not `MultiLineString`")
        else:
            match += 1
        # validate data type: MultiPoint
        if not isinstance(v, MultiPoint):
            error_messages.append(f"Error! Input type `{type(v)}` is not `MultiPoint`")
        else:
            match += 1
        # validate data type: MultiPolygon
        if not isinstance(v, MultiPolygon):
            error_messages.append(f"Error! Input type `{type(v)}` is not `MultiPolygon`")
        else:
            match += 1
        # validate data type: Point
        if not isinstance(v, Point):
            error_messages.append(f"Error! Input type `{type(v)}` is not `Point`")
        else:
            match += 1
        # validate data type: Polygon
        if not isinstance(v, Polygon):
            error_messages.append(f"Error! Input type `{type(v)}` is not `Polygon`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in GeometryCollectionAllOfGeometries with oneOf schemas: Feature, FeatureCollection, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in GeometryCollectionAllOfGeometries with oneOf schemas: Feature, FeatureCollection, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon. Details: " + ", ".join(error_messages))
        else:
            return v

    @classmethod
    def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self:
        return cls.from_json(json.dumps(obj))

    @classmethod
    def from_json(cls, json_str: str) -> Self:
        """Returns the object represented by the json string"""
        instance = cls.model_construct()
        error_messages = []
        match = 0

        # deserialize data into Feature
        try:
            instance.actual_instance = Feature.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into FeatureCollection
        try:
            instance.actual_instance = FeatureCollection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into GeometryCollection
        try:
            instance.actual_instance = GeometryCollection.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into LineString
        try:
            instance.actual_instance = LineString.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into MultiLineString
        try:
            instance.actual_instance = MultiLineString.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into MultiPoint
        try:
            instance.actual_instance = MultiPoint.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into MultiPolygon
        try:
            instance.actual_instance = MultiPolygon.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into Point
        try:
            instance.actual_instance = Point.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into Polygon
        try:
            instance.actual_instance = Polygon.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))

        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when deserializing the JSON string into GeometryCollectionAllOfGeometries with oneOf schemas: Feature, FeatureCollection, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into GeometryCollectionAllOfGeometries with oneOf schemas: Feature, FeatureCollection, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon. Details: " + ", ".join(error_messages))
        else:
            return instance

    def to_json(self) -> str:
        """Returns the JSON representation of the actual instance"""
        if self.actual_instance is None:
            return "null"

        if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json):
            return self.actual_instance.to_json()
        else:
            return json.dumps(self.actual_instance)

    def to_dict(self) -> Optional[Union[Dict[str, Any], Feature, FeatureCollection, GeometryCollection, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon]]:
        """Returns the dict representation of the actual instance"""
        if self.actual_instance is None:
            return None

        if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict):
            return self.actual_instance.to_dict()
        else:
            # primitive type
            return self.actual_instance

    def to_str(self) -> str:
        """Returns the string representation of the actual instance"""
        return pprint.pformat(self.model_dump())

from skyledge_sdk.models.feature import Feature
from skyledge_sdk.models.feature_collection import FeatureCollection
from skyledge_sdk.models.geometry_collection import GeometryCollection
# TODO: Rewrite to not use raise_errors
GeometryCollectionAllOfGeometries.model_rebuild(raise_errors=False)

