# coding: utf-8

"""
    Secore API

    API for the Seres core platform

    The version of the OpenAPI document: 0.1.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, StrictInt
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from seres_client.models.flight_plan_schema_leg_schema import FlightPlanSchemaLegSchema
from seres_client.models.flight_plan_schema_type import FlightPlanSchemaType
from seres_client.models.flight_plan_schema_waypoint_schema import FlightPlanSchemaWaypointSchema
from seres_client.models.flight_plan_type_enum import FlightPlanTypeEnum
from seres_client.models.implementation_status_enum import ImplementationStatusEnum
from typing import Optional, Set
from typing_extensions import Self

class FlightPlanSchemaSchema(BaseModel):
    """
    FlightPlanSchemaSchema
    """ # noqa: E501
    type: FlightPlanSchemaType
    flight_plan_type: Optional[FlightPlanTypeEnum] = None
    reference: Annotated[str, Field(strict=True, max_length=120)]
    waypoints: List[FlightPlanSchemaWaypointSchema]
    legs: List[FlightPlanSchemaLegSchema]
    revision_of_id: Optional[StrictInt] = None
    variation_of_id: Optional[StrictInt] = None
    id: StrictInt
    account_id: StrictInt
    status: ImplementationStatusEnum
    __properties: ClassVar[List[str]] = ["type", "flight_plan_type", "reference", "waypoints", "legs", "revision_of_id", "variation_of_id", "id", "account_id", "status"]

    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 FlightPlanSchemaSchema 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 waypoints (list)
        _items = []
        if self.waypoints:
            for _item_waypoints in self.waypoints:
                if _item_waypoints:
                    _items.append(_item_waypoints.to_dict())
            _dict['waypoints'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in legs (list)
        _items = []
        if self.legs:
            for _item_legs in self.legs:
                if _item_legs:
                    _items.append(_item_legs.to_dict())
            _dict['legs'] = _items
        # set to None if revision_of_id (nullable) is None
        # and model_fields_set contains the field
        if self.revision_of_id is None and "revision_of_id" in self.model_fields_set:
            _dict['revision_of_id'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "type": obj.get("type"),
            "flight_plan_type": obj.get("flight_plan_type"),
            "reference": obj.get("reference"),
            "waypoints": [FlightPlanSchemaWaypointSchema.from_dict(_item) for _item in obj["waypoints"]] if obj.get("waypoints") is not None else None,
            "legs": [FlightPlanSchemaLegSchema.from_dict(_item) for _item in obj["legs"]] if obj.get("legs") is not None else None,
            "revision_of_id": obj.get("revision_of_id"),
            "variation_of_id": obj.get("variation_of_id"),
            "id": obj.get("id"),
            "account_id": obj.get("account_id"),
            "status": obj.get("status")
        })
        return _obj


