# To use this code, make sure you
#
#     import json
#
# and then, to convert JSON from a string, do
#
#     result = external_integration_bot_exchange_request_from_dict(json.loads(json_string))

from dataclasses import dataclass
from typing import Optional, Any, TypeVar, Type, cast


T = TypeVar("T")


def from_int(x: Any) -> int:
    assert isinstance(x, int) and not isinstance(x, bool)
    return x


def from_none(x: Any) -> Any:
    assert x is None
    return x


def from_union(fs, x):
    for f in fs:
        try:
            return f(x)
        except:
            pass
    assert False


def from_str(x: Any) -> str:
    assert isinstance(x, str)
    return x


def to_class(c: Type[T], x: Any) -> dict:
    assert isinstance(x, c)
    return cast(Any, x).to_dict()


@dataclass
class BotConfig:
    value_kind: Optional[int] = None

    @staticmethod
    def from_dict(obj: Any) -> 'BotConfig':
        assert isinstance(obj, dict)
        value_kind = from_union([from_int, from_none], obj.get("ValueKind"))
        return BotConfig(value_kind)

    def to_dict(self) -> dict:
        result: dict = {}
        result["ValueKind"] = from_union([from_int, from_none], self.value_kind)
        return result


@dataclass
class ExecutionInfo:
    contact_id: Optional[int] = None
    bus_no: Optional[int] = None
    request_id: Optional[int] = None
    action_type: Optional[str] = None
    action_id: Optional[int] = None
    script_name: Optional[str] = None

    @staticmethod
    def from_dict(obj: Any) -> 'ExecutionInfo':
        assert isinstance(obj, dict)
        contact_id = from_union([from_int, from_none], obj.get("contactId"))
        bus_no = from_union([from_int, from_none], obj.get("busNo"))
        request_id = from_union([from_int, from_none], obj.get("requestId"))
        action_type = from_union([from_str, from_none], obj.get("actionType"))
        action_id = from_union([from_int, from_none], obj.get("actionId"))
        script_name = from_union([from_str, from_none], obj.get("scriptName"))
        return ExecutionInfo(contact_id, bus_no, request_id, action_type, action_id, script_name)

    def to_dict(self) -> dict:
        result: dict = {}
        result["contactId"] = from_union([from_int, from_none], self.contact_id)
        result["busNo"] = from_union([from_int, from_none], self.bus_no)
        result["requestId"] = from_union([from_int, from_none], self.request_id)
        result["actionType"] = from_union([from_str, from_none], self.action_type)
        result["actionId"] = from_union([from_int, from_none], self.action_id)
        result["scriptName"] = from_union([from_str, from_none], self.script_name)
        return result


@dataclass
class ExternalIntegrationBotExchangeRequest:
    system_telemetry_data: None
    base64_wav_file: None
    bot_session_state: None
    custom_payload: None
    virtual_agent_id: Optional[str] = None
    bot_config: Optional[BotConfig] = None
    user_input: Optional[str] = None
    user_input_type: Optional[int] = None
    execution_info: Optional[ExecutionInfo] = None
    media_type: Optional[str] = None

    @staticmethod
    def from_dict(obj: Any) -> 'ExternalIntegrationBotExchangeRequest':
        assert isinstance(obj, dict)
        system_telemetry_data = from_none(obj.get("systemTelemetryData"))
        base64_wav_file = obj.get("base64wavFile")
        bot_session_state = from_none(obj.get("botSessionState"))
        custom_payload = obj.get("customPayload")
        virtual_agent_id = from_union([from_str, from_none], obj.get("virtualAgentId"))
        bot_config = from_union([BotConfig.from_dict, from_none], obj.get("botConfig"))
        user_input = from_union([from_str, from_none], obj.get("userInput"))
        user_input_type = from_union([from_int, from_none], obj.get("userInputType"))
        execution_info = from_union([ExecutionInfo.from_dict, from_none], obj.get("executionInfo"))
        media_type = from_union([from_str, from_none], obj.get("mediaType"))
        return ExternalIntegrationBotExchangeRequest(system_telemetry_data, base64_wav_file, bot_session_state, custom_payload, virtual_agent_id, bot_config, user_input, user_input_type, execution_info, media_type)

    def to_dict(self) -> dict:
        result: dict = {}
        result["systemTelemetryData"] = from_none(self.system_telemetry_data)
        result["base64wavFile"] = from_none(self.base64_wav_file)
        result["botSessionState"] = from_none(self.bot_session_state)
        result["customPayload"] = from_none(self.custom_payload)
        result["virtualAgentId"] = from_union([from_str, from_none], self.virtual_agent_id)
        result["botConfig"] = from_union([lambda x: to_class(BotConfig, x), from_none], self.bot_config)
        result["userInput"] = from_union([from_str, from_none], self.user_input)
        result["userInputType"] = from_union([from_int, from_none], self.user_input_type)
        result["executionInfo"] = from_union([lambda x: to_class(ExecutionInfo, x), from_none], self.execution_info)
        result["mediaType"] = from_union([from_str, from_none], self.media_type)
        return result


def external_integration_bot_exchange_request_from_dict(s: Any) -> ExternalIntegrationBotExchangeRequest:
    return ExternalIntegrationBotExchangeRequest.from_dict(s)


def external_integration_bot_exchange_request_to_dict(x: ExternalIntegrationBotExchangeRequest) -> Any:
    return to_class(ExternalIntegrationBotExchangeRequest, x)
