# coding: utf-8

"""
    Cyberwave API

    Cyberwave platform REST API. Use 'Bearer YOUR_TOKEN' for authentication.

    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 pydantic import BaseModel, ConfigDict, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from cyberwave.rest.models.navigation_waypoint_schema import NavigationWaypointSchema
from typing import Optional, Set
from typing_extensions import Self

class TwinNavigationCommandSchema(BaseModel):
    """
    TwinNavigationCommandSchema
    """ # noqa: E501
    command: StrictStr
    position: Optional[List[Union[StrictFloat, StrictInt]]] = None
    rotation: Optional[List[Union[StrictFloat, StrictInt]]] = None
    yaw: Optional[Union[StrictFloat, StrictInt]] = None
    waypoints: Optional[List[NavigationWaypointSchema]] = None
    controller_policy_uuid: Optional[StrictStr] = None
    environment_uuid: Optional[StrictStr] = None
    source_type: Optional[StrictStr] = None
    constraints: Optional[Dict[str, Any]] = None
    metadata: Optional[Dict[str, Any]] = None
    __properties: ClassVar[List[str]] = ["command", "position", "rotation", "yaw", "waypoints", "controller_policy_uuid", "environment_uuid", "source_type", "constraints", "metadata"]

    @field_validator('command')
    def command_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['goto', 'path', 'stop', 'pause', 'resume']):
            raise ValueError("must be one of enum values ('goto', 'path', 'stop', 'pause', 'resume')")
        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 TwinNavigationCommandSchema 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
        # set to None if position (nullable) is None
        # and model_fields_set contains the field
        if self.position is None and "position" in self.model_fields_set:
            _dict['position'] = None

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "command": obj.get("command"),
            "position": obj.get("position"),
            "rotation": obj.get("rotation"),
            "yaw": obj.get("yaw"),
            "waypoints": [NavigationWaypointSchema.from_dict(_item) for _item in obj["waypoints"]] if obj.get("waypoints") is not None else None,
            "controller_policy_uuid": obj.get("controller_policy_uuid"),
            "environment_uuid": obj.get("environment_uuid"),
            "source_type": obj.get("source_type"),
            "constraints": obj.get("constraints"),
            "metadata": obj.get("metadata")
        })
        return _obj


