# coding: utf-8

"""
    

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional

from pydantic import BaseModel, Field, StrictStr
from typing_extensions import Annotated

try:
    from typing import Self
except ImportError:
    from typing_extensions import Self


class Run(BaseModel):
    """
    Run
    """  # noqa: E501

    id: Optional[Annotated[str, Field(strict=True, max_length=100)]] = None
    answer: StrictStr
    session_name: Optional[StrictStr] = None
    name: Optional[StrictStr] = None
    reference_example_id: Optional[StrictStr] = None
    start_time: StrictStr
    end_time: Optional[StrictStr] = None
    extra: Optional[Dict[str, Any]] = None
    events: Optional[Dict[str, Any]] = None
    outputs: Optional[Dict[str, Any]] = None
    serialized: Optional[Dict[str, Any]] = None
    inputs: Optional[Dict[str, Any]] = None
    error: Optional[StrictStr] = None
    run_type: Optional[StrictStr] = None
    execution_order: Optional[
        Annotated[int, Field(le=2147483647, strict=True, ge=-2147483648)]
    ] = None
    child_execution_order: Optional[StrictStr] = None
    parent_run_id: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = [
        "id",
        "answer",
        "session_name",
        "name",
        "reference_example_id",
        "start_time",
        "end_time",
        "extra",
        "events",
        "outputs",
        "serialized",
        "inputs",
        "error",
        "run_type",
        "execution_order",
        "child_execution_order",
        "parent_run_id",
    ]

    model_config = {
        "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) -> Self:
        """Create an instance of Run 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.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={},
            exclude_none=True,
        )
        # set to None if session_name (nullable) is None
        # and model_fields_set contains the field
        if self.session_name is None and "session_name" in self.model_fields_set:
            _dict["session_name"] = None

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Dict) -> Self:
        """Create an instance of Run from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate(
            {
                "id": obj.get("id"),
                "answer": obj.get("answer"),
                "session_name": obj.get("session_name"),
                "name": obj.get("name"),
                "reference_example_id": obj.get("reference_example_id"),
                "start_time": obj.get("start_time"),
                "end_time": obj.get("end_time"),
                "extra": obj.get("extra"),
                "events": obj.get("events"),
                "outputs": obj.get("outputs"),
                "serialized": obj.get("serialized"),
                "inputs": obj.get("inputs"),
                "error": obj.get("error"),
                "run_type": obj.get("run_type"),
                "execution_order": obj.get("execution_order"),
                "child_execution_order": obj.get("child_execution_order"),
                "parent_run_id": obj.get("parent_run_id"),
            }
        )
        return _obj
