# 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.models.agents_execution_activity_action_completed_payload import AgentsExecutionActivityActionCompletedPayload
from asteroid_odyssey.models.agents_execution_activity_action_failed_payload import AgentsExecutionActivityActionFailedPayload
from asteroid_odyssey.models.agents_execution_activity_action_started_payload import AgentsExecutionActivityActionStartedPayload
from asteroid_odyssey.models.agents_execution_activity_file_added_payload import AgentsExecutionActivityFileAddedPayload
from asteroid_odyssey.models.agents_execution_activity_generic_payload import AgentsExecutionActivityGenericPayload
from asteroid_odyssey.models.agents_execution_activity_playwright_script_generated_payload import AgentsExecutionActivityPlaywrightScriptGeneratedPayload
from asteroid_odyssey.models.agents_execution_activity_reasoning_payload import AgentsExecutionActivityReasoningPayload
from asteroid_odyssey.models.agents_execution_activity_status_changed_payload import AgentsExecutionActivityStatusChangedPayload
from asteroid_odyssey.models.agents_execution_activity_step_completed_payload import AgentsExecutionActivityStepCompletedPayload
from asteroid_odyssey.models.agents_execution_activity_step_started_payload import AgentsExecutionActivityStepStartedPayload
from asteroid_odyssey.models.agents_execution_activity_transitioned_node_payload import AgentsExecutionActivityTransitionedNodePayload
from asteroid_odyssey.models.agents_execution_activity_user_message_received_payload import AgentsExecutionActivityUserMessageReceivedPayload
from asteroid_odyssey.models.agents_execution_activity_workflow_updated_payload import AgentsExecutionActivityWorkflowUpdatedPayload
from asteroid_odyssey.models.agents_execution_terminal_payload import AgentsExecutionTerminalPayload
from pydantic import StrictStr, Field
from typing import Union, List, Set, Optional, Dict
from typing_extensions import Literal, Self

AGENTSEXECUTIONACTIVITYPAYLOADUNION_ONE_OF_SCHEMAS = ["AgentsExecutionActivityActionCompletedPayload", "AgentsExecutionActivityActionFailedPayload", "AgentsExecutionActivityActionStartedPayload", "AgentsExecutionActivityFileAddedPayload", "AgentsExecutionActivityGenericPayload", "AgentsExecutionActivityPlaywrightScriptGeneratedPayload", "AgentsExecutionActivityReasoningPayload", "AgentsExecutionActivityStatusChangedPayload", "AgentsExecutionActivityStepCompletedPayload", "AgentsExecutionActivityStepStartedPayload", "AgentsExecutionActivityTransitionedNodePayload", "AgentsExecutionActivityUserMessageReceivedPayload", "AgentsExecutionActivityWorkflowUpdatedPayload", "AgentsExecutionTerminalPayload"]

class AgentsExecutionActivityPayloadUnion(BaseModel):
    """
    AgentsExecutionActivityPayloadUnion
    """
    # data type: AgentsExecutionTerminalPayload
    oneof_schema_1_validator: Optional[AgentsExecutionTerminalPayload] = None
    # data type: AgentsExecutionActivityGenericPayload
    oneof_schema_2_validator: Optional[AgentsExecutionActivityGenericPayload] = None
    # data type: AgentsExecutionActivityReasoningPayload
    oneof_schema_3_validator: Optional[AgentsExecutionActivityReasoningPayload] = None
    # data type: AgentsExecutionActivityStepStartedPayload
    oneof_schema_4_validator: Optional[AgentsExecutionActivityStepStartedPayload] = None
    # data type: AgentsExecutionActivityStepCompletedPayload
    oneof_schema_5_validator: Optional[AgentsExecutionActivityStepCompletedPayload] = None
    # data type: AgentsExecutionActivityTransitionedNodePayload
    oneof_schema_6_validator: Optional[AgentsExecutionActivityTransitionedNodePayload] = None
    # data type: AgentsExecutionActivityStatusChangedPayload
    oneof_schema_7_validator: Optional[AgentsExecutionActivityStatusChangedPayload] = None
    # data type: AgentsExecutionActivityActionStartedPayload
    oneof_schema_8_validator: Optional[AgentsExecutionActivityActionStartedPayload] = None
    # data type: AgentsExecutionActivityActionCompletedPayload
    oneof_schema_9_validator: Optional[AgentsExecutionActivityActionCompletedPayload] = None
    # data type: AgentsExecutionActivityActionFailedPayload
    oneof_schema_10_validator: Optional[AgentsExecutionActivityActionFailedPayload] = None
    # data type: AgentsExecutionActivityUserMessageReceivedPayload
    oneof_schema_11_validator: Optional[AgentsExecutionActivityUserMessageReceivedPayload] = None
    # data type: AgentsExecutionActivityFileAddedPayload
    oneof_schema_12_validator: Optional[AgentsExecutionActivityFileAddedPayload] = None
    # data type: AgentsExecutionActivityWorkflowUpdatedPayload
    oneof_schema_13_validator: Optional[AgentsExecutionActivityWorkflowUpdatedPayload] = None
    # data type: AgentsExecutionActivityPlaywrightScriptGeneratedPayload
    oneof_schema_14_validator: Optional[AgentsExecutionActivityPlaywrightScriptGeneratedPayload] = None
    actual_instance: Optional[Union[AgentsExecutionActivityActionCompletedPayload, AgentsExecutionActivityActionFailedPayload, AgentsExecutionActivityActionStartedPayload, AgentsExecutionActivityFileAddedPayload, AgentsExecutionActivityGenericPayload, AgentsExecutionActivityPlaywrightScriptGeneratedPayload, AgentsExecutionActivityReasoningPayload, AgentsExecutionActivityStatusChangedPayload, AgentsExecutionActivityStepCompletedPayload, AgentsExecutionActivityStepStartedPayload, AgentsExecutionActivityTransitionedNodePayload, AgentsExecutionActivityUserMessageReceivedPayload, AgentsExecutionActivityWorkflowUpdatedPayload, AgentsExecutionTerminalPayload]] = None
    one_of_schemas: Set[str] = { "AgentsExecutionActivityActionCompletedPayload", "AgentsExecutionActivityActionFailedPayload", "AgentsExecutionActivityActionStartedPayload", "AgentsExecutionActivityFileAddedPayload", "AgentsExecutionActivityGenericPayload", "AgentsExecutionActivityPlaywrightScriptGeneratedPayload", "AgentsExecutionActivityReasoningPayload", "AgentsExecutionActivityStatusChangedPayload", "AgentsExecutionActivityStepCompletedPayload", "AgentsExecutionActivityStepStartedPayload", "AgentsExecutionActivityTransitionedNodePayload", "AgentsExecutionActivityUserMessageReceivedPayload", "AgentsExecutionActivityWorkflowUpdatedPayload", "AgentsExecutionTerminalPayload" }

    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: AgentsExecutionTerminalPayload
        if not isinstance(v, AgentsExecutionTerminalPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionTerminalPayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityGenericPayload
        if not isinstance(v, AgentsExecutionActivityGenericPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityGenericPayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityReasoningPayload
        if not isinstance(v, AgentsExecutionActivityReasoningPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityReasoningPayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityStepStartedPayload
        if not isinstance(v, AgentsExecutionActivityStepStartedPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityStepStartedPayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityStepCompletedPayload
        if not isinstance(v, AgentsExecutionActivityStepCompletedPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityStepCompletedPayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityTransitionedNodePayload
        if not isinstance(v, AgentsExecutionActivityTransitionedNodePayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityTransitionedNodePayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityStatusChangedPayload
        if not isinstance(v, AgentsExecutionActivityStatusChangedPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityStatusChangedPayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityActionStartedPayload
        if not isinstance(v, AgentsExecutionActivityActionStartedPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityActionStartedPayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityActionCompletedPayload
        if not isinstance(v, AgentsExecutionActivityActionCompletedPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityActionCompletedPayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityActionFailedPayload
        if not isinstance(v, AgentsExecutionActivityActionFailedPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityActionFailedPayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityUserMessageReceivedPayload
        if not isinstance(v, AgentsExecutionActivityUserMessageReceivedPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityUserMessageReceivedPayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityFileAddedPayload
        if not isinstance(v, AgentsExecutionActivityFileAddedPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityFileAddedPayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityWorkflowUpdatedPayload
        if not isinstance(v, AgentsExecutionActivityWorkflowUpdatedPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityWorkflowUpdatedPayload`")
        else:
            match += 1
        # validate data type: AgentsExecutionActivityPlaywrightScriptGeneratedPayload
        if not isinstance(v, AgentsExecutionActivityPlaywrightScriptGeneratedPayload):
            error_messages.append(f"Error! Input type `{type(v)}` is not `AgentsExecutionActivityPlaywrightScriptGeneratedPayload`")
        else:
            match += 1
        if match > 1:
            # more than 1 match
            raise ValueError("Multiple matches found when setting `actual_instance` in AgentsExecutionActivityPayloadUnion with oneOf schemas: AgentsExecutionActivityActionCompletedPayload, AgentsExecutionActivityActionFailedPayload, AgentsExecutionActivityActionStartedPayload, AgentsExecutionActivityFileAddedPayload, AgentsExecutionActivityGenericPayload, AgentsExecutionActivityPlaywrightScriptGeneratedPayload, AgentsExecutionActivityReasoningPayload, AgentsExecutionActivityStatusChangedPayload, AgentsExecutionActivityStepCompletedPayload, AgentsExecutionActivityStepStartedPayload, AgentsExecutionActivityTransitionedNodePayload, AgentsExecutionActivityUserMessageReceivedPayload, AgentsExecutionActivityWorkflowUpdatedPayload, AgentsExecutionTerminalPayload. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when setting `actual_instance` in AgentsExecutionActivityPayloadUnion with oneOf schemas: AgentsExecutionActivityActionCompletedPayload, AgentsExecutionActivityActionFailedPayload, AgentsExecutionActivityActionStartedPayload, AgentsExecutionActivityFileAddedPayload, AgentsExecutionActivityGenericPayload, AgentsExecutionActivityPlaywrightScriptGeneratedPayload, AgentsExecutionActivityReasoningPayload, AgentsExecutionActivityStatusChangedPayload, AgentsExecutionActivityStepCompletedPayload, AgentsExecutionActivityStepStartedPayload, AgentsExecutionActivityTransitionedNodePayload, AgentsExecutionActivityUserMessageReceivedPayload, AgentsExecutionActivityWorkflowUpdatedPayload, AgentsExecutionTerminalPayload. 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 AgentsExecutionTerminalPayload
        try:
            instance.actual_instance = AgentsExecutionTerminalPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityGenericPayload
        try:
            instance.actual_instance = AgentsExecutionActivityGenericPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityReasoningPayload
        try:
            instance.actual_instance = AgentsExecutionActivityReasoningPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityStepStartedPayload
        try:
            instance.actual_instance = AgentsExecutionActivityStepStartedPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityStepCompletedPayload
        try:
            instance.actual_instance = AgentsExecutionActivityStepCompletedPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityTransitionedNodePayload
        try:
            instance.actual_instance = AgentsExecutionActivityTransitionedNodePayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityStatusChangedPayload
        try:
            instance.actual_instance = AgentsExecutionActivityStatusChangedPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityActionStartedPayload
        try:
            instance.actual_instance = AgentsExecutionActivityActionStartedPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityActionCompletedPayload
        try:
            instance.actual_instance = AgentsExecutionActivityActionCompletedPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityActionFailedPayload
        try:
            instance.actual_instance = AgentsExecutionActivityActionFailedPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityUserMessageReceivedPayload
        try:
            instance.actual_instance = AgentsExecutionActivityUserMessageReceivedPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityFileAddedPayload
        try:
            instance.actual_instance = AgentsExecutionActivityFileAddedPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityWorkflowUpdatedPayload
        try:
            instance.actual_instance = AgentsExecutionActivityWorkflowUpdatedPayload.from_json(json_str)
            match += 1
        except (ValidationError, ValueError) as e:
            error_messages.append(str(e))
        # deserialize data into AgentsExecutionActivityPlaywrightScriptGeneratedPayload
        try:
            instance.actual_instance = AgentsExecutionActivityPlaywrightScriptGeneratedPayload.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: AgentsExecutionActivityActionCompletedPayload, AgentsExecutionActivityActionFailedPayload, AgentsExecutionActivityActionStartedPayload, AgentsExecutionActivityFileAddedPayload, AgentsExecutionActivityGenericPayload, AgentsExecutionActivityPlaywrightScriptGeneratedPayload, AgentsExecutionActivityReasoningPayload, AgentsExecutionActivityStatusChangedPayload, AgentsExecutionActivityStepCompletedPayload, AgentsExecutionActivityStepStartedPayload, AgentsExecutionActivityTransitionedNodePayload, AgentsExecutionActivityUserMessageReceivedPayload, AgentsExecutionActivityWorkflowUpdatedPayload, AgentsExecutionTerminalPayload. Details: " + ", ".join(error_messages))
        elif match == 0:
            # no match
            raise ValueError("No match found when deserializing the JSON string into AgentsExecutionActivityPayloadUnion with oneOf schemas: AgentsExecutionActivityActionCompletedPayload, AgentsExecutionActivityActionFailedPayload, AgentsExecutionActivityActionStartedPayload, AgentsExecutionActivityFileAddedPayload, AgentsExecutionActivityGenericPayload, AgentsExecutionActivityPlaywrightScriptGeneratedPayload, AgentsExecutionActivityReasoningPayload, AgentsExecutionActivityStatusChangedPayload, AgentsExecutionActivityStepCompletedPayload, AgentsExecutionActivityStepStartedPayload, AgentsExecutionActivityTransitionedNodePayload, AgentsExecutionActivityUserMessageReceivedPayload, AgentsExecutionActivityWorkflowUpdatedPayload, AgentsExecutionTerminalPayload. 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], AgentsExecutionActivityActionCompletedPayload, AgentsExecutionActivityActionFailedPayload, AgentsExecutionActivityActionStartedPayload, AgentsExecutionActivityFileAddedPayload, AgentsExecutionActivityGenericPayload, AgentsExecutionActivityPlaywrightScriptGeneratedPayload, AgentsExecutionActivityReasoningPayload, AgentsExecutionActivityStatusChangedPayload, AgentsExecutionActivityStepCompletedPayload, AgentsExecutionActivityStepStartedPayload, AgentsExecutionActivityTransitionedNodePayload, AgentsExecutionActivityUserMessageReceivedPayload, AgentsExecutionActivityWorkflowUpdatedPayload, AgentsExecutionTerminalPayload]]:
        """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())


