# 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 BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from freeclimb.models.answered_by import AnsweredBy
from freeclimb.models.call_direction import CallDirection
from freeclimb.models.call_status import CallStatus
from pydantic import StrictStr
from typing import Optional, Set
from typing_extensions import Self


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

    uri: Optional[StrictStr] = Field(
        default=None, description="The URI for this resource, relative to /apiserver."
    )
    date_created: Optional[StrictStr] = Field(
        default=None,
        description="The date that this resource was created (GMT) in RFC 1123 format (e.g., Mon, 15 Jun 2009 20:45:30 GMT).",
        alias="dateCreated",
    )
    date_updated: Optional[StrictStr] = Field(
        default=None,
        description="The date that this resource was last updated (GMT) in RFC 1123 format (e.g., Mon, 15 Jun 2009 20:45:30 GMT).",
        alias="dateUpdated",
    )
    revision: Optional[StrictInt] = Field(
        default=None,
        description="Revision count for the resource. This count is set to 1 on creation and is incremented every time it is updated.",
    )
    call_id: Optional[StrictStr] = Field(
        default=None,
        description="String that uniquely identifies this Call resource.",
        alias="callId",
    )
    parent_call_id: Optional[StrictStr] = Field(
        default=None,
        description="ID of the Call that created this leg (child Call).",
        alias="parentCallId",
    )
    account_id: Optional[StrictStr] = Field(
        default=None,
        description="ID of the account that owns this Call.",
        alias="accountId",
    )
    var_from: Optional[StrictStr] = Field(
        default=None, description="Phone number that initiated this Call.", alias="from"
    )
    to: Optional[StrictStr] = Field(
        default=None, description="Phone number that received this Call."
    )
    phone_number_id: Optional[StrictStr] = Field(
        default=None,
        description="If the Call was inbound, this is the ID of the IncomingPhoneNumber that received the Call (DNIS). If the Call was outbound, this is the ID of the phone number from which the Call was placed (ANI).",
        alias="phoneNumberId",
    )
    call_status: Optional[CallStatus] = Field(default=None, alias="callStatus")
    start_time: Optional[StrictStr] = Field(
        default=None,
        description="Start time of the Call (GMT) in RFC 1123 format (e.g., Mon, 15 Jun 2009 20:45:30 GMT). Empty if the Call has not yet been dialed.",
        alias="startTime",
    )
    connect_time: Optional[StrictStr] = Field(
        default=None,
        description="Time the Call was answered (GMT) in RFC 1123 format (e.g., Mon, 15 Jun 2009 20:45:30 GMT). Empty if the Call has not yet been dialed.",
        alias="connectTime",
    )
    end_time: Optional[StrictStr] = Field(
        default=None,
        description="End time of the Call (GMT) in RFC 1123 format (e.g., Mon, 15 Jun 2009 20:45:30 GMT). Empty if the Call did not complete successfully.",
        alias="endTime",
    )
    duration: Optional[StrictInt] = Field(
        default=None,
        description="Total length of the Call in seconds. Measures time between startTime and endTime. This value is empty for busy, failed, unanswered or ongoing Calls.",
    )
    connect_duration: Optional[StrictInt] = Field(
        default=None,
        description="Length of time that the Call was connected in seconds. Measures time between connectTime and endTime. This value is empty for busy, failed, unanswered or ongoing Calls.",
        alias="connectDuration",
    )
    direction: Optional[CallDirection] = None
    answered_by: Optional[AnsweredBy] = Field(default=None, alias="answeredBy")
    subresource_uris: Optional[Dict[str, Any]] = Field(
        default=None,
        description="The list of subresources for this Call. These include things like logs and recordings associated with the Call.",
        alias="subresourceUris",
    )
    application_id: Optional[StrictStr] = Field(
        default=None,
        description="ApplicationId associated with the Call.",
        alias="applicationId",
    )

    __properties: ClassVar[List[str]] = [
        "uri",
        "dateCreated",
        "dateUpdated",
        "revision",
        "callId",
        "parentCallId",
        "accountId",
        "from",
        "to",
        "phoneNumberId",
        "callStatus",
        "startTime",
        "connectTime",
        "endTime",
        "duration",
        "connectDuration",
        "direction",
        "answeredBy",
        "subresourceUris",
        "applicationId",
    ]

    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 CallResult 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,
        )
        # set to None if call_id (nullable) is None
        # and model_fields_set contains the field
        if self.call_id is None and "call_id" in self.model_fields_set:
            _dict["callId"] = None

        # set to None if parent_call_id (nullable) is None
        # and model_fields_set contains the field
        if self.parent_call_id is None and "parent_call_id" in self.model_fields_set:
            _dict["parentCallId"] = None

        # set to None if account_id (nullable) is None
        # and model_fields_set contains the field
        if self.account_id is None and "account_id" in self.model_fields_set:
            _dict["accountId"] = None

        # set to None if var_from (nullable) is None
        # and model_fields_set contains the field
        if self.var_from is None and "var_from" in self.model_fields_set:
            _dict["from"] = None

        # set to None if to (nullable) is None
        # and model_fields_set contains the field
        if self.to is None and "to" in self.model_fields_set:
            _dict["to"] = None

        # set to None if phone_number_id (nullable) is None
        # and model_fields_set contains the field
        if self.phone_number_id is None and "phone_number_id" in self.model_fields_set:
            _dict["phoneNumberId"] = None

        # set to None if call_status (nullable) is None
        # and model_fields_set contains the field
        if self.call_status is None and "call_status" in self.model_fields_set:
            _dict["callStatus"] = None

        # set to None if start_time (nullable) is None
        # and model_fields_set contains the field
        if self.start_time is None and "start_time" in self.model_fields_set:
            _dict["startTime"] = None

        # set to None if connect_time (nullable) is None
        # and model_fields_set contains the field
        if self.connect_time is None and "connect_time" in self.model_fields_set:
            _dict["connectTime"] = None

        # set to None if end_time (nullable) is None
        # and model_fields_set contains the field
        if self.end_time is None and "end_time" in self.model_fields_set:
            _dict["endTime"] = None

        # set to None if duration (nullable) is None
        # and model_fields_set contains the field
        if self.duration is None and "duration" in self.model_fields_set:
            _dict["duration"] = None

        # set to None if connect_duration (nullable) is None
        # and model_fields_set contains the field
        if (
            self.connect_duration is None
            and "connect_duration" in self.model_fields_set
        ):
            _dict["connectDuration"] = None

        # set to None if direction (nullable) is None
        # and model_fields_set contains the field
        if self.direction is None and "direction" in self.model_fields_set:
            _dict["direction"] = None

        # set to None if answered_by (nullable) is None
        # and model_fields_set contains the field
        if self.answered_by is None and "answered_by" in self.model_fields_set:
            _dict["answeredBy"] = None

        # set to None if subresource_uris (nullable) is None
        # and model_fields_set contains the field
        if (
            self.subresource_uris is None
            and "subresource_uris" in self.model_fields_set
        ):
            _dict["subresourceUris"] = None

        # set to None if application_id (nullable) is None
        # and model_fields_set contains the field
        if self.application_id is None and "application_id" in self.model_fields_set:
            _dict["applicationId"] = None

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "uri": obj.get("uri"),
                "dateCreated": obj.get("dateCreated"),
                "dateUpdated": obj.get("dateUpdated"),
                "revision": obj.get("revision"),
                "callId": obj.get("callId"),
                "parentCallId": obj.get("parentCallId"),
                "accountId": obj.get("accountId"),
                "from": obj.get("from"),
                "to": obj.get("to"),
                "phoneNumberId": obj.get("phoneNumberId"),
                "callStatus": obj.get("callStatus"),
                "startTime": obj.get("startTime"),
                "connectTime": obj.get("connectTime"),
                "endTime": obj.get("endTime"),
                "duration": obj.get("duration"),
                "connectDuration": obj.get("connectDuration"),
                "direction": obj.get("direction"),
                "answeredBy": obj.get("answeredBy"),
                "subresourceUris": obj.get("subresourceUris"),
                "applicationId": obj.get("applicationId"),
            }
        )
        return _obj
