# 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 pydantic import ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from freeclimb.models.percl_command import PerclCommand
from pydantic import StrictStr
from typing import Optional, Set
from typing_extensions import Self


class GetDigits(
    PerclCommand,
    populate_by_name=True,
    validate_assignment=True,
    protected_namespaces=(),
):
    """
    The `GetDigits` command collects DTMF inputs from the caller. It is only supported only when there is a single party on the Call. `GetDigits` is a Terminal Command — any actions following it are never executed. When the Caller is done entering the digits, FreeClimb submits that data to the provided `actionUrl` using an HTTP POST request. Your server will be required to respond to the FreeClimb Webhook with PerCL to continue handling the call.
    """  # noqa: E501

    action_url: StrictStr = Field(
        description="When the Caller has finished entering digits, FreeClimb will make an HTTP POST request to this URL. A PerCL response is expected to continue handling the Call. Make sure to keep “http://“ in the URL.",
        alias="actionUrl",
    )
    digit_timeout_ms: Optional[StrictInt] = Field(
        default=None,
        description=" Maximum time in milliseconds that FreeClimb will wait for the Caller to press any digit after the last digit entered, before making a determination that a `timeout` has occurred and moving on to make the request to the actionUrl to submit the results of the `GetDigits` command. This timeout interval begins and resets after each digit entered.",
        alias="digitTimeoutMs",
    )
    finish_on_key: Optional[StrictStr] = Field(
        default=None,
        description="Digit that causes the input sequence to be deemed complete. This attribute defers to the `timeout` attribute – so, if a `timeout` occurs, then the command terminates regardless of the value of `finishOnKey`.",
        alias="finishOnKey",
    )
    flush_buffer: Optional[StrictBool] = Field(
        default=None,
        description="If set to true, the FreeClimb platform starts with an empty DTMF buffer to store the digits entered by the caller. If set to false, FreeClimb will append the user inputs to the end of the existing digits buffer and will return digits from the start of the digits buffer.",
        alias="flushBuffer",
    )
    initial_timeout_ms: Optional[StrictInt] = Field(
        default=None,
        description="Maximum time in milliseconds that FreeClimb will wait for the Caller to press the first digit before making a determination that a `timeout` has occurred and moving on to make the request to the `actionUrl` to submit the results of the `GetDigits` command. This timeout interval begins when all nested commands have been fully executed.",
        alias="initialTimeoutMs",
    )
    max_digits: Optional[StrictInt] = Field(
        default=None,
        description="Maximum number of digits expected in the input. If the terminating digit is not entered and the caller has entered the maximum number of digits allowed, the `GetDigits` command terminates regardless of the value of `finishOnKey`.",
        alias="maxDigits",
    )
    min_digits: Optional[StrictInt] = Field(
        default=None,
        description="Minimum number of digits expected in the input. If specified, FreeClimb will return the collected digits only if the Caller has entered at least that many digits.",
        alias="minDigits",
    )
    prompts: Optional[List[PerclCommand]] = Field(
        default=None,
        description="JSON array of PerCL commands to nest within the `GetDigits` command. The `Say`, `Play`, and `Pause` commands can be used. The nested actions are executed while FreeClimb is waiting for input from the Caller.",
    )
    privacy_mode: Optional[StrictBool] = Field(
        default=None,
        description="Parameter `privacyMode` will not log the `text` as required by PCI compliance.",
        alias="privacyMode",
    )
    command: StrictStr = "GetDigits"

    __properties: ClassVar[List[str]] = [
        "command",
        "actionUrl",
        "digitTimeoutMs",
        "finishOnKey",
        "flushBuffer",
        "initialTimeoutMs",
        "maxDigits",
        "minDigits",
        "prompts",
        "privacyMode",
    ]

    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[Self]:
        """Create an instance of GetDigits 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,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in prompts (list)
        _items = []
        if self.prompts:
            for _item_prompts in self.prompts:
                if _item_prompts:
                    _items.append(_item_prompts.to_dict())
            _dict["prompts"] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of GetDigits from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate(
            {
                "command": obj.get("command"),
                "actionUrl": obj.get("actionUrl"),
                "digitTimeoutMs": obj.get("digitTimeoutMs"),
                "finishOnKey": obj.get("finishOnKey"),
                "flushBuffer": obj.get("flushBuffer"),
                "initialTimeoutMs": obj.get("initialTimeoutMs"),
                "maxDigits": obj.get("maxDigits"),
                "minDigits": obj.get("minDigits"),
                "prompts": (
                    [PerclCommand.from_dict(_item) for _item in obj["prompts"]]
                    if obj.get("prompts") is not None
                    else None
                ),
                "privacyMode": obj.get("privacyMode"),
            }
        )
        return _obj
