# 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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from freeclimb.models.message_status import MessageStatus
from freeclimb.models.tfn import TFN
from pydantic import StrictStr
from typing import Optional, Set
from typing_extensions import Self


class MessageResult(
    BaseModel, populate_by_name=True, validate_assignment=True, protected_namespaces=()
):
    """
    MessageResult
    """  # 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.",
    )
    account_id: Optional[StrictStr] = Field(
        default=None,
        description="String that uniquely identifies this account resource.",
        alias="accountId",
    )
    message_id: Optional[StrictStr] = Field(
        default=None,
        description="String that uniquely identifies this message resource",
        alias="messageId",
    )
    status: Optional[MessageStatus] = None
    var_from: Optional[StrictStr] = Field(
        default=None,
        description="Phone number in E.164 format that sent the message.",
        alias="from",
    )
    to: Optional[StrictStr] = Field(
        default=None,
        description="Phone number in E.164 format that received the message.",
    )
    text: Optional[StrictStr] = Field(default=None, description="Message contents")
    direction: Optional[StrictStr] = Field(
        default=None, description="Noting whether the message was inbound or outbound"
    )
    notification_url: Optional[StrictStr] = Field(
        default=None,
        description="URL invoked when message sent",
        alias="notificationUrl",
    )
    brand_id: Optional[StrictStr] = Field(
        default=None,
        description="The unique identifier for the brand associated with the message",
        alias="brandId",
    )
    campaign_id: Optional[StrictStr] = Field(
        default=None,
        description="The unique identifier for the campaign associated with the message",
        alias="campaignId",
    )
    segment_count: Optional[Union[StrictFloat, StrictInt]] = Field(
        default=None,
        description="The number of segments into which the message was split",
        alias="segmentCount",
    )
    media_urls: Optional[List[StrictStr]] = Field(
        default=None,
        description="an array of HTTP URLs which were attached this this message",
        alias="mediaUrls",
    )
    tfn: Optional[TFN] = None
    phone_number_id: Optional[StrictStr] = Field(
        default=None,
        description="String that uniquely identifies the phoneNumber resource used to send this Message",
        alias="phoneNumberId",
    )
    application_id: Optional[StrictStr] = Field(
        default=None,
        description="String that uniquely identifies the Application resource used to send this Message",
        alias="applicationId",
    )

    __properties: ClassVar[List[str]] = [
        "uri",
        "dateCreated",
        "dateUpdated",
        "revision",
        "accountId",
        "messageId",
        "status",
        "from",
        "to",
        "text",
        "direction",
        "notificationUrl",
        "brandId",
        "campaignId",
        "segmentCount",
        "mediaUrls",
        "tfn",
        "phoneNumberId",
        "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 MessageResult 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 tfn
        if self.tfn:
            _dict["tfn"] = self.tfn.to_dict()
        # 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 message_id (nullable) is None
        # and model_fields_set contains the field
        if self.message_id is None and "message_id" in self.model_fields_set:
            _dict["messageId"] = None

        # set to None if status (nullable) is None
        # and model_fields_set contains the field
        if self.status is None and "status" in self.model_fields_set:
            _dict["status"] = 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 text (nullable) is None
        # and model_fields_set contains the field
        if self.text is None and "text" in self.model_fields_set:
            _dict["text"] = 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 notification_url (nullable) is None
        # and model_fields_set contains the field
        if (
            self.notification_url is None
            and "notification_url" in self.model_fields_set
        ):
            _dict["notificationUrl"] = None

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

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

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

        # set to None if media_urls (nullable) is None
        # and model_fields_set contains the field
        if self.media_urls is None and "media_urls" in self.model_fields_set:
            _dict["mediaUrls"] = 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 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 MessageResult 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"),
                "accountId": obj.get("accountId"),
                "messageId": obj.get("messageId"),
                "status": obj.get("status"),
                "from": obj.get("from"),
                "to": obj.get("to"),
                "text": obj.get("text"),
                "direction": obj.get("direction"),
                "notificationUrl": obj.get("notificationUrl"),
                "brandId": obj.get("brandId"),
                "campaignId": obj.get("campaignId"),
                "segmentCount": obj.get("segmentCount"),
                "mediaUrls": obj.get("mediaUrls"),
                "tfn": (
                    TFN.from_dict(obj["tfn"]) if obj.get("tfn") is not None else None
                ),
                "phoneNumberId": obj.get("phoneNumberId"),
                "applicationId": obj.get("applicationId"),
            }
        )
        return _obj
