# 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, StrictBool, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from cyberwave.rest.models.motion_plan_schema import MotionPlanSchema
from typing import Optional, Set
from typing_extensions import Self

class TwinActionRequestSchema(BaseModel):
    """
    TwinActionRequestSchema
    """ # noqa: E501
    action_type: StrictStr
    name: Optional[StrictStr] = None
    plan: Optional[MotionPlanSchema] = None
    joints: Optional[Dict[str, Union[StrictFloat, StrictInt]]] = None
    scope: Optional[StrictStr] = 'auto'
    environment_uuid: Optional[StrictStr] = None
    execution: Optional[StrictStr] = 'async'
    preview: Optional[StrictBool] = False
    source_type: Optional[StrictStr] = None
    tick_ms: Optional[StrictInt] = None
    transition_ms: Optional[StrictInt] = None
    hold_ms: Optional[StrictInt] = None
    __properties: ClassVar[List[str]] = ["action_type", "name", "plan", "joints", "scope", "environment_uuid", "execution", "preview", "source_type", "tick_ms", "transition_ms", "hold_ms"]

    @field_validator('execution')
    def execution_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['async']):
            raise ValueError("must be one of enum values ('async')")
        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 TwinActionRequestSchema 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 plan
        if self.plan:
            _dict['plan'] = self.plan.to_dict()
        # set to None if name (nullable) is None
        # and model_fields_set contains the field
        if self.name is None and "name" in self.model_fields_set:
            _dict['name'] = None

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

        # set to None if joints (nullable) is None
        # and model_fields_set contains the field
        if self.joints is None and "joints" in self.model_fields_set:
            _dict['joints'] = 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 tick_ms (nullable) is None
        # and model_fields_set contains the field
        if self.tick_ms is None and "tick_ms" in self.model_fields_set:
            _dict['tick_ms'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "action_type": obj.get("action_type"),
            "name": obj.get("name"),
            "plan": MotionPlanSchema.from_dict(obj["plan"]) if obj.get("plan") is not None else None,
            "joints": obj.get("joints"),
            "scope": obj.get("scope") if obj.get("scope") is not None else 'auto',
            "environment_uuid": obj.get("environment_uuid"),
            "execution": obj.get("execution") if obj.get("execution") is not None else 'async',
            "preview": obj.get("preview") if obj.get("preview") is not None else False,
            "source_type": obj.get("source_type"),
            "tick_ms": obj.get("tick_ms"),
            "transition_ms": obj.get("transition_ms"),
            "hold_ms": obj.get("hold_ms")
        })
        return _obj


