# coding: utf-8

"""
    Klaviyo API

    The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details.

    Contact: developers@klaviyo.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class SMSTransactional(BaseModel):
    """
    SMSTransactional
    """ # noqa: E501
    can_receive_sms_transactional: StrictBool = Field(description="Whether or not this profile is subscribed to receive transactional SMS.")
    consent: StrictStr = Field(description="The consent status for SMS Transactional.")
    consent_timestamp: Optional[datetime] = Field(default=None, description="The timestamp when consent was recorded or updated for Transactional SMS messaging , in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm).")
    method: Optional[StrictStr] = Field(default=None, description="The method by which the profile was subscribed to Transactional SMS messaging .")
    method_detail: Optional[StrictStr] = Field(default='', description="Additional details about the method which the profile was subscribed to Transactional SMS messaging. This may be empty if no details were provided.")
    last_updated: Optional[datetime] = Field(default=None, description="The timestamp when the SMS consent record was last modified, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm).")
    __properties: ClassVar[List[str]] = ["can_receive_sms_transactional", "consent", "consent_timestamp", "method", "method_detail", "last_updated"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    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 SMSTransactional 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 consent_timestamp (nullable) is None
        # and model_fields_set contains the field
        if self.consent_timestamp is None and "consent_timestamp" in self.model_fields_set:
            _dict['consent_timestamp'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "can_receive_sms_transactional": obj.get("can_receive_sms_transactional"),
            "consent": obj.get("consent"),
            "consent_timestamp": obj.get("consent_timestamp"),
            "method": obj.get("method"),
            "method_detail": obj.get("method_detail") if obj.get("method_detail") is not None else '',
            "last_updated": obj.get("last_updated")
        })
        return _obj


