# coding: utf-8

"""
    FreeClimb API

    FreeClimb is a cloud-based application programming interface (API) that puts the power of the Vail platform in your hands. FreeClimb simplifies the process of creating applications that can use a full range of telephony features without requiring specialized or on-site telephony equipment. Using the FreeClimb REST API to write applications is easy! You have the option to use the language of your choice or hit the API directly. Your application can execute a command by issuing a RESTful request to the FreeClimb API. The base URL to send HTTP requests to the FreeClimb REST API is: /apiserver. FreeClimb authenticates and processes your request.

    The version of the OpenAPI document: 1.0.0
    Contact: support@freeclimb.com
    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 importlib import import_module
from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from pydantic import StrictStr
from typing import Optional, Set
from typing_extensions import Self

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from freeclimb.models.add_to_conference_notification_webhook import (
        AddToConferenceNotificationWebhook,
    )
    from freeclimb.models.add_to_queue_notification_webhook import (
        AddToQueueNotificationWebhook,
    )
    from freeclimb.models.call_control_webhook import CallControlWebhook
    from freeclimb.models.call_status_webhook import CallStatusWebhook
    from freeclimb.models.conference_recording_status_webhook import (
        ConferenceRecordingStatusWebhook,
    )
    from freeclimb.models.conference_status_webhook import ConferenceStatusWebhook
    from freeclimb.models.create_conference_webhook import CreateConferenceWebhook
    from freeclimb.models.dequeue_webhook import DequeueWebhook
    from freeclimb.models.get_digits_webhook import GetDigitsWebhook
    from freeclimb.models.get_speech_webhook import GetSpeechWebhook
    from freeclimb.models.inbound_call_webhook import InboundCallWebhook
    from freeclimb.models.leave_conference_webhook import LeaveConferenceWebhook
    from freeclimb.models.machine_detected_webhook import MachineDetectedWebhook
    from freeclimb.models.message_delivery_webhook import MessageDeliveryWebhook
    from freeclimb.models.message_status_webhook import MessageStatusWebhook
    from freeclimb.models.out_dial_api_connect_webhook import OutDialApiConnectWebhook
    from freeclimb.models.out_dial_connect_webhook import OutDialConnectWebhook
    from freeclimb.models.out_dial_start_webhook import OutDialStartWebhook
    from freeclimb.models.queue_wait_webhook import QueueWaitWebhook
    from freeclimb.models.record_webhook import RecordWebhook
    from freeclimb.models.redirect_webhook import RedirectWebhook
    from freeclimb.models.remove_from_queue_notification_webhook import (
        RemoveFromQueueNotificationWebhook,
    )
    from freeclimb.models.transcribe_webhook import TranscribeWebhook


class Webhook(
    BaseModel, populate_by_name=True, validate_assignment=True, protected_namespaces=()
):
    """
    Webhook
    """  # noqa: E501

    request_type: Optional[StrictStr] = Field(
        default=None, description="Type of webhook request", alias="requestType"
    )

    __properties: ClassVar[List[str]] = ["requestType"]

    # JSON field name that stores the object type
    __discriminator_property_name: ClassVar[str] = "requestType"

    # discriminator mappings
    __discriminator_value_class_map: ClassVar[Dict[str, str]] = {
        "addToConferenceNotification": "AddToConferenceNotificationWebhook",
        "addToQueueNotification": "AddToQueueNotificationWebhook",
        "callControl": "CallControlWebhook",
        "callStatus": "CallStatusWebhook",
        "conferenceRecordingStatus": "ConferenceRecordingStatusWebhook",
        "conferenceStatus": "ConferenceStatusWebhook",
        "createConference": "CreateConferenceWebhook",
        "dequeue": "DequeueWebhook",
        "getDigits": "GetDigitsWebhook",
        "getSpeech": "GetSpeechWebhook",
        "inboundCall": "InboundCallWebhook",
        "leaveConference": "LeaveConferenceWebhook",
        "machineDetected": "MachineDetectedWebhook",
        "messageDelivery": "MessageDeliveryWebhook",
        "messageStatus": "MessageStatusWebhook",
        "outDialApiConnect": "OutDialApiConnectWebhook",
        "outDialConnect": "OutDialConnectWebhook",
        "outDialStart": "OutDialStartWebhook",
        "queueWait": "QueueWaitWebhook",
        "record": "RecordWebhook",
        "redirect": "RedirectWebhook",
        "removeFromQueueNotification": "RemoveFromQueueNotificationWebhook",
        "transcribe": "TranscribeWebhook",
    }

    @classmethod
    def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]:
        """Returns the discriminator value (object type) of the data"""
        discriminator_value = obj[cls.__discriminator_property_name]
        if discriminator_value:
            return cls.__discriminator_value_class_map.get(discriminator_value)
        else:
            return None

    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[
        Union[
            AddToConferenceNotificationWebhook,
            AddToQueueNotificationWebhook,
            CallControlWebhook,
            CallStatusWebhook,
            ConferenceRecordingStatusWebhook,
            ConferenceStatusWebhook,
            CreateConferenceWebhook,
            DequeueWebhook,
            GetDigitsWebhook,
            GetSpeechWebhook,
            InboundCallWebhook,
            LeaveConferenceWebhook,
            MachineDetectedWebhook,
            MessageDeliveryWebhook,
            MessageStatusWebhook,
            OutDialApiConnectWebhook,
            OutDialConnectWebhook,
            OutDialStartWebhook,
            QueueWaitWebhook,
            RecordWebhook,
            RedirectWebhook,
            RemoveFromQueueNotificationWebhook,
            TranscribeWebhook,
        ]
    ]:
        """Create an instance of Webhook 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,
        )
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict[str, Any]) -> Optional[
        Union[
            AddToConferenceNotificationWebhook,
            AddToQueueNotificationWebhook,
            CallControlWebhook,
            CallStatusWebhook,
            ConferenceRecordingStatusWebhook,
            ConferenceStatusWebhook,
            CreateConferenceWebhook,
            DequeueWebhook,
            GetDigitsWebhook,
            GetSpeechWebhook,
            InboundCallWebhook,
            LeaveConferenceWebhook,
            MachineDetectedWebhook,
            MessageDeliveryWebhook,
            MessageStatusWebhook,
            OutDialApiConnectWebhook,
            OutDialConnectWebhook,
            OutDialStartWebhook,
            QueueWaitWebhook,
            RecordWebhook,
            RedirectWebhook,
            RemoveFromQueueNotificationWebhook,
            TranscribeWebhook,
        ]
    ]:
        """Create an instance of Webhook from a dict"""
        # look up the object type based on discriminator mapping
        object_type = cls.get_discriminator_value(obj)
        if object_type == "AddToConferenceNotificationWebhook":
            return import_module(
                "freeclimb.models.add_to_conference_notification_webhook"
            ).AddToConferenceNotificationWebhook.from_dict(obj)
        if object_type == "AddToQueueNotificationWebhook":
            return import_module(
                "freeclimb.models.add_to_queue_notification_webhook"
            ).AddToQueueNotificationWebhook.from_dict(obj)
        if object_type == "CallControlWebhook":
            return import_module(
                "freeclimb.models.call_control_webhook"
            ).CallControlWebhook.from_dict(obj)
        if object_type == "CallStatusWebhook":
            return import_module(
                "freeclimb.models.call_status_webhook"
            ).CallStatusWebhook.from_dict(obj)
        if object_type == "ConferenceRecordingStatusWebhook":
            return import_module(
                "freeclimb.models.conference_recording_status_webhook"
            ).ConferenceRecordingStatusWebhook.from_dict(obj)
        if object_type == "ConferenceStatusWebhook":
            return import_module(
                "freeclimb.models.conference_status_webhook"
            ).ConferenceStatusWebhook.from_dict(obj)
        if object_type == "CreateConferenceWebhook":
            return import_module(
                "freeclimb.models.create_conference_webhook"
            ).CreateConferenceWebhook.from_dict(obj)
        if object_type == "DequeueWebhook":
            return import_module(
                "freeclimb.models.dequeue_webhook"
            ).DequeueWebhook.from_dict(obj)
        if object_type == "GetDigitsWebhook":
            return import_module(
                "freeclimb.models.get_digits_webhook"
            ).GetDigitsWebhook.from_dict(obj)
        if object_type == "GetSpeechWebhook":
            return import_module(
                "freeclimb.models.get_speech_webhook"
            ).GetSpeechWebhook.from_dict(obj)
        if object_type == "InboundCallWebhook":
            return import_module(
                "freeclimb.models.inbound_call_webhook"
            ).InboundCallWebhook.from_dict(obj)
        if object_type == "LeaveConferenceWebhook":
            return import_module(
                "freeclimb.models.leave_conference_webhook"
            ).LeaveConferenceWebhook.from_dict(obj)
        if object_type == "MachineDetectedWebhook":
            return import_module(
                "freeclimb.models.machine_detected_webhook"
            ).MachineDetectedWebhook.from_dict(obj)
        if object_type == "MessageDeliveryWebhook":
            return import_module(
                "freeclimb.models.message_delivery_webhook"
            ).MessageDeliveryWebhook.from_dict(obj)
        if object_type == "MessageStatusWebhook":
            return import_module(
                "freeclimb.models.message_status_webhook"
            ).MessageStatusWebhook.from_dict(obj)
        if object_type == "OutDialApiConnectWebhook":
            return import_module(
                "freeclimb.models.out_dial_api_connect_webhook"
            ).OutDialApiConnectWebhook.from_dict(obj)
        if object_type == "OutDialConnectWebhook":
            return import_module(
                "freeclimb.models.out_dial_connect_webhook"
            ).OutDialConnectWebhook.from_dict(obj)
        if object_type == "OutDialStartWebhook":
            return import_module(
                "freeclimb.models.out_dial_start_webhook"
            ).OutDialStartWebhook.from_dict(obj)
        if object_type == "QueueWaitWebhook":
            return import_module(
                "freeclimb.models.queue_wait_webhook"
            ).QueueWaitWebhook.from_dict(obj)
        if object_type == "RecordWebhook":
            return import_module(
                "freeclimb.models.record_webhook"
            ).RecordWebhook.from_dict(obj)
        if object_type == "RedirectWebhook":
            return import_module(
                "freeclimb.models.redirect_webhook"
            ).RedirectWebhook.from_dict(obj)
        if object_type == "RemoveFromQueueNotificationWebhook":
            return import_module(
                "freeclimb.models.remove_from_queue_notification_webhook"
            ).RemoveFromQueueNotificationWebhook.from_dict(obj)
        if object_type == "TranscribeWebhook":
            return import_module(
                "freeclimb.models.transcribe_webhook"
            ).TranscribeWebhook.from_dict(obj)

        raise ValueError(
            "Webhook failed to lookup discriminator value from "
            + json.dumps(obj)
            + ". Discriminator property name: "
            + cls.__discriminator_property_name
            + ", mapping: "
            + json.dumps(cls.__discriminator_value_class_map)
        )
