# 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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from seres_client.models.flight_plan_leg_schema import FlightPlanLegSchema
from seres_client.models.flight_plan_type_enum import FlightPlanTypeEnum
from seres_client.models.flight_plan_waypoint_schema import FlightPlanWaypointSchema
from typing import Optional, Set
from typing_extensions import Self

class FlightPlanSchema(BaseModel):
    """
    FlightPlanSchema
    """ # noqa: E501
    reference: Annotated[str, Field(strict=True, max_length=120)]
    flight_plan_schema_id: Optional[StrictInt] = None
    parent_flight_plan_id: Optional[StrictInt] = None
    account_id: StrictInt
    is_private: Optional[StrictBool] = False
    type: Optional[FlightPlanTypeEnum] = None
    id: StrictInt
    future_id: StrictInt
    created_by_id: StrictInt
    created: StrictStr
    cancelled: StrictBool
    origin_port_id: Optional[StrictInt] = None
    destination_port_id: Optional[StrictInt] = None
    offgrid_origin: Optional[StrictBool] = None
    offgrid_destination: Optional[StrictBool] = None
    legs: List[FlightPlanLegSchema]
    waypoints: List[FlightPlanWaypointSchema]
    __properties: ClassVar[List[str]] = ["reference", "flight_plan_schema_id", "parent_flight_plan_id", "account_id", "is_private", "type", "id", "future_id", "created_by_id", "created", "cancelled", "origin_port_id", "destination_port_id", "offgrid_origin", "offgrid_destination", "legs", "waypoints"]

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "reference": obj.get("reference"),
            "flight_plan_schema_id": obj.get("flight_plan_schema_id"),
            "parent_flight_plan_id": obj.get("parent_flight_plan_id"),
            "account_id": obj.get("account_id"),
            "is_private": obj.get("is_private") if obj.get("is_private") is not None else False,
            "type": obj.get("type"),
            "id": obj.get("id"),
            "future_id": obj.get("future_id"),
            "created_by_id": obj.get("created_by_id"),
            "created": obj.get("created"),
            "cancelled": obj.get("cancelled"),
            "origin_port_id": obj.get("origin_port_id"),
            "destination_port_id": obj.get("destination_port_id"),
            "offgrid_origin": obj.get("offgrid_origin"),
            "offgrid_destination": obj.get("offgrid_destination"),
            "legs": [FlightPlanLegSchema.from_dict(_item) for _item in obj["legs"]] if obj.get("legs") is not None else None,
            "waypoints": [FlightPlanWaypointSchema.from_dict(_item) for _item in obj["waypoints"]] if obj.get("waypoints") is not None else None
        })
        return _obj


