# coding: utf-8

"""
    Agent Service

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

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

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


from __future__ import annotations
import json
import pprint
from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator
from typing import Any, List, Optional
from asteroid_odyssey.agents_v2_gen.models.activity_payload_union_action_completed import ActivityPayloadUnionActionCompleted
from asteroid_odyssey.agents_v2_gen.models.activity_payload_union_action_failed import ActivityPayloadUnionActionFailed
from asteroid_odyssey.agents_v2_gen.models.activity_payload_union_action_started import ActivityPayloadUnionActionStarted
from asteroid_odyssey.agents_v2_gen.models.activity_payload_union_file_added import ActivityPayloadUnionFileAdded
from asteroid_odyssey.agents_v2_gen.models.activity_payload_union_generic import ActivityPayloadUnionGeneric
from asteroid_odyssey.agents_v2_gen.models.activity_payload_union_graph_updated import ActivityPayloadUnionGraphUpdated
from asteroid_odyssey.agents_v2_gen.models.activity_payload_union_status_changed import ActivityPayloadUnionStatusChanged
from asteroid_odyssey.agents_v2_gen.models.activity_payload_union_step_completed import ActivityPayloadUnionStepCompleted
from asteroid_odyssey.agents_v2_gen.models.activity_payload_union_step_started import ActivityPayloadUnionStepStarted
from asteroid_odyssey.agents_v2_gen.models.activity_payload_union_terminal import ActivityPayloadUnionTerminal
from asteroid_odyssey.agents_v2_gen.models.activity_payload_union_transitioned_node import ActivityPayloadUnionTransitionedNode
from asteroid_odyssey.agents_v2_gen.models.activity_payload_union_user_message_received import ActivityPayloadUnionUserMessageReceived
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

AGENTSEXECUTIONACTIVITYPAYLOADUNION_ONE_OF_SCHEMAS = ["ActivityPayloadUnionActionCompleted", "ActivityPayloadUnionActionFailed", "ActivityPayloadUnionActionStarted", "ActivityPayloadUnionFileAdded", "ActivityPayloadUnionGeneric", "ActivityPayloadUnionGraphUpdated", "ActivityPayloadUnionStatusChanged", "ActivityPayloadUnionStepCompleted", "ActivityPayloadUnionStepStarted", "ActivityPayloadUnionTerminal", "ActivityPayloadUnionTransitionedNode", "ActivityPayloadUnionUserMessageReceived"]

class AgentsExecutionActivityPayloadUnion(BaseModel):
    """
    AgentsExecutionActivityPayloadUnion
    """
    # data type: ActivityPayloadUnionTerminal
    oneof_schema_1_validator: Optional[ActivityPayloadUnionTerminal] = None
    # data type: ActivityPayloadUnionGeneric
    oneof_schema_2_validator: Optional[ActivityPayloadUnionGeneric] = None
    # data type: ActivityPayloadUnionStepStarted
    oneof_schema_3_validator: Optional[ActivityPayloadUnionStepStarted] = None
    # data type: ActivityPayloadUnionStepCompleted
    oneof_schema_4_validator: Optional[ActivityPayloadUnionStepCompleted] = None
    # data type: ActivityPayloadUnionTransitionedNode
    oneof_schema_5_validator: Optional[ActivityPayloadUnionTransitionedNode] = None
    # data type: ActivityPayloadUnionStatusChanged
    oneof_schema_6_validator: Optional[ActivityPayloadUnionStatusChanged] = None
    # data type: ActivityPayloadUnionActionStarted
    oneof_schema_7_validator: Optional[ActivityPayloadUnionActionStarted] = None
    # data type: ActivityPayloadUnionActionCompleted
    oneof_schema_8_validator: Optional[ActivityPayloadUnionActionCompleted] = None
    # data type: ActivityPayloadUnionActionFailed
    oneof_schema_9_validator: Optional[ActivityPayloadUnionActionFailed] = None
    # data type: ActivityPayloadUnionUserMessageReceived
    oneof_schema_10_validator: Optional[ActivityPayloadUnionUserMessageReceived] = None
    # data type: ActivityPayloadUnionFileAdded
    oneof_schema_11_validator: Optional[ActivityPayloadUnionFileAdded] = None
    # data type: ActivityPayloadUnionGraphUpdated
    oneof_schema_12_validator: Optional[ActivityPayloadUnionGraphUpdated] = None
    actual_instance: Optional[Union[ActivityPayloadUnionActionCompleted, ActivityPayloadUnionActionFailed, ActivityPayloadUnionActionStarted, ActivityPayloadUnionFileAdded, ActivityPayloadUnionGeneric, ActivityPayloadUnionGraphUpdated, ActivityPayloadUnionStatusChanged, ActivityPayloadUnionStepCompleted, ActivityPayloadUnionStepStarted, ActivityPayloadUnionTerminal, ActivityPayloadUnionTransitionedNode, ActivityPayloadUnionUserMessageReceived]] = None
    one_of_schemas: Set[str] = { "ActivityPayloadUnionActionCompleted", "ActivityPayloadUnionActionFailed", "ActivityPayloadUnionActionStarted", "ActivityPayloadUnionFileAdded", "ActivityPayloadUnionGeneric", "ActivityPayloadUnionGraphUpdated", "ActivityPayloadUnionStatusChanged", "ActivityPayloadUnionStepCompleted", "ActivityPayloadUnionStepStarted", "ActivityPayloadUnionTerminal", "ActivityPayloadUnionTransitionedNode", "ActivityPayloadUnionUserMessageReceived" }

    model_config = ConfigDict(
        validate_assignment=True,
        protected_namespaces=(),
    )


    discriminator_value_class_map: Dict[str, str] = {
    }

    def __init__(self, *args, **kwargs) -> None:
        if args:
            if len(args) > 1:
                raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`")
            if kwargs:
                raise ValueError("If a position argument is used, keyword arguments cannot be used.")
            super().__init__(actual_instance=args[0])
        else:
            super().__init__(**kwargs)

    @field_validator('actual_instance')
    def actual_instance_must_validate_oneof(cls, v):
        instance = AgentsExecutionActivityPayloadUnion.model_construct()
        error_messages = []
        match = 0
        # validate data type: ActivityPayloadUnionTerminal
        if not isinstance(v, ActivityPayloadUnionTerminal):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ActivityPayloadUnionTerminal`")
        else:
            match += 1
        # validate data type: ActivityPayloadUnionGeneric
        if not isinstance(v, ActivityPayloadUnionGeneric):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ActivityPayloadUnionGeneric`")
        else:
            match += 1
        # validate data type: ActivityPayloadUnionStepStarted
        if not isinstance(v, ActivityPayloadUnionStepStarted):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ActivityPayloadUnionStepStarted`")
        else:
            match += 1
        # validate data type: ActivityPayloadUnionStepCompleted
        if not isinstance(v, ActivityPayloadUnionStepCompleted):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ActivityPayloadUnionStepCompleted`")
        else:
            match += 1
        # validate data type: ActivityPayloadUnionTransitionedNode
        if not isinstance(v, ActivityPayloadUnionTransitionedNode):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ActivityPayloadUnionTransitionedNode`")
        else:
            match += 1
        # validate data type: ActivityPayloadUnionStatusChanged
        if not isinstance(v, ActivityPayloadUnionStatusChanged):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ActivityPayloadUnionStatusChanged`")
        else:
            match += 1
        # validate data type: ActivityPayloadUnionActionStarted
        if not isinstance(v, ActivityPayloadUnionActionStarted):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ActivityPayloadUnionActionStarted`")
        else:
            match += 1
        # validate data type: ActivityPayloadUnionActionCompleted
        if not isinstance(v, ActivityPayloadUnionActionCompleted):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ActivityPayloadUnionActionCompleted`")
        else:
            match += 1
        # validate data type: ActivityPayloadUnionActionFailed
        if not isinstance(v, ActivityPayloadUnionActionFailed):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ActivityPayloadUnionActionFailed`")
        else:
            match += 1
        # validate data type: ActivityPayloadUnionUserMessageReceived
        if not isinstance(v, ActivityPayloadUnionUserMessageReceived):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ActivityPayloadUnionUserMessageReceived`")
        else:
            match += 1
        # validate data type: ActivityPayloadUnionFileAdded
        if not isinstance(v, ActivityPayloadUnionFileAdded):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ActivityPayloadUnionFileAdded`")
        else:
            match += 1
        # validate data type: ActivityPayloadUnionGraphUpdated
        if not isinstance(v, ActivityPayloadUnionGraphUpdated):
            error_messages.append(f"Error! Input type `{type(v)}` is not `ActivityPayloadUnionGraphUpdated`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in AgentsExecutionActivityPayloadUnion with oneOf schemas: ActivityPayloadUnionActionCompleted, ActivityPayloadUnionActionFailed, ActivityPayloadUnionActionStarted, ActivityPayloadUnionFileAdded, ActivityPayloadUnionGeneric, ActivityPayloadUnionGraphUpdated, ActivityPayloadUnionStatusChanged, ActivityPayloadUnionStepCompleted, ActivityPayloadUnionStepStarted, ActivityPayloadUnionTerminal, ActivityPayloadUnionTransitionedNode, ActivityPayloadUnionUserMessageReceived. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in AgentsExecutionActivityPayloadUnion with oneOf schemas: ActivityPayloadUnionActionCompleted, ActivityPayloadUnionActionFailed, ActivityPayloadUnionActionStarted, ActivityPayloadUnionFileAdded, ActivityPayloadUnionGeneric, ActivityPayloadUnionGraphUpdated, ActivityPayloadUnionStatusChanged, ActivityPayloadUnionStepCompleted, ActivityPayloadUnionStepStarted, ActivityPayloadUnionTerminal, ActivityPayloadUnionTransitionedNode, ActivityPayloadUnionUserMessageReceived. Details: " + ", ".join(error_messages))
        else:
            return v

    @classmethod
    def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self:
        return cls.from_json(json.dumps(obj))

    @classmethod
    def from_json(cls, json_str: str) -> Self:
        """Returns the object represented by the json string"""
        instance = cls.model_construct()
        error_messages = []
        match = 0

        # deserialize data into ActivityPayloadUnionTerminal
        try:
            instance.actual_instance = ActivityPayloadUnionTerminal.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ActivityPayloadUnionGeneric
        try:
            instance.actual_instance = ActivityPayloadUnionGeneric.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ActivityPayloadUnionStepStarted
        try:
            instance.actual_instance = ActivityPayloadUnionStepStarted.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ActivityPayloadUnionStepCompleted
        try:
            instance.actual_instance = ActivityPayloadUnionStepCompleted.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ActivityPayloadUnionTransitionedNode
        try:
            instance.actual_instance = ActivityPayloadUnionTransitionedNode.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ActivityPayloadUnionStatusChanged
        try:
            instance.actual_instance = ActivityPayloadUnionStatusChanged.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ActivityPayloadUnionActionStarted
        try:
            instance.actual_instance = ActivityPayloadUnionActionStarted.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ActivityPayloadUnionActionCompleted
        try:
            instance.actual_instance = ActivityPayloadUnionActionCompleted.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ActivityPayloadUnionActionFailed
        try:
            instance.actual_instance = ActivityPayloadUnionActionFailed.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ActivityPayloadUnionUserMessageReceived
        try:
            instance.actual_instance = ActivityPayloadUnionUserMessageReceived.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ActivityPayloadUnionFileAdded
        try:
            instance.actual_instance = ActivityPayloadUnionFileAdded.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into ActivityPayloadUnionGraphUpdated
        try:
            instance.actual_instance = ActivityPayloadUnionGraphUpdated.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))

        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when deserializing the JSON string into AgentsExecutionActivityPayloadUnion with oneOf schemas: ActivityPayloadUnionActionCompleted, ActivityPayloadUnionActionFailed, ActivityPayloadUnionActionStarted, ActivityPayloadUnionFileAdded, ActivityPayloadUnionGeneric, ActivityPayloadUnionGraphUpdated, ActivityPayloadUnionStatusChanged, ActivityPayloadUnionStepCompleted, ActivityPayloadUnionStepStarted, ActivityPayloadUnionTerminal, ActivityPayloadUnionTransitionedNode, ActivityPayloadUnionUserMessageReceived. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into AgentsExecutionActivityPayloadUnion with oneOf schemas: ActivityPayloadUnionActionCompleted, ActivityPayloadUnionActionFailed, ActivityPayloadUnionActionStarted, ActivityPayloadUnionFileAdded, ActivityPayloadUnionGeneric, ActivityPayloadUnionGraphUpdated, ActivityPayloadUnionStatusChanged, ActivityPayloadUnionStepCompleted, ActivityPayloadUnionStepStarted, ActivityPayloadUnionTerminal, ActivityPayloadUnionTransitionedNode, ActivityPayloadUnionUserMessageReceived. Details: " + ", ".join(error_messages))
        else:
            return instance

    def to_json(self) -> str:
        """Returns the JSON representation of the actual instance"""
        if self.actual_instance is None:
            return "null"

        if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json):
            return self.actual_instance.to_json()
        else:
            return json.dumps(self.actual_instance)

    def to_dict(self) -> Optional[Union[Dict[str, Any], ActivityPayloadUnionActionCompleted, ActivityPayloadUnionActionFailed, ActivityPayloadUnionActionStarted, ActivityPayloadUnionFileAdded, ActivityPayloadUnionGeneric, ActivityPayloadUnionGraphUpdated, ActivityPayloadUnionStatusChanged, ActivityPayloadUnionStepCompleted, ActivityPayloadUnionStepStarted, ActivityPayloadUnionTerminal, ActivityPayloadUnionTransitionedNode, ActivityPayloadUnionUserMessageReceived]]:
        """Returns the dict representation of the actual instance"""
        if self.actual_instance is None:
            return None

        if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict):
            return self.actual_instance.to_dict()
        else:
            # primitive type
            return self.actual_instance

    def to_str(self) -> str:
        """Returns the string representation of the actual instance"""
        return pprint.pformat(self.model_dump())


