# coding: utf-8

"""
    One-API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 2.0
    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, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from bsg_api.models.phone import Phone
from bsg_api.models.whats_app_message_alternative_channel import WhatsAppMessageAlternativeChannel
from bsg_api.models.whats_app_message_template import WhatsAppMessageTemplate
from typing import Optional, Set
from typing_extensions import Self

class WhatsAppMessage(BaseModel):
    """
    WhatsAppMessage
    """ # noqa: E501
    phone: Phone
    sender: Annotated[str, Field(min_length=1, strict=True, max_length=40)]
    type: StrictStr
    template: Optional[WhatsAppMessageTemplate] = None
    alternative_channel: Optional[WhatsAppMessageAlternativeChannel] = None
    callback_url: Optional[Any] = Field(default=None, description="Link to get the delivery status of messages. If this parameter is specified in the method, it will take precedence over the value specified in the “Callback URL” field in the Personal Area.")
    add_to_contact_book: Optional[StrictBool] = True
    check_stop_list: Optional[StrictBool] = True
    __properties: ClassVar[List[str]] = ["phone", "sender", "type", "template", "alternative_channel", "callback_url", "add_to_contact_book", "check_stop_list"]

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['template']):
            raise ValueError("must be one of enum values ('template')")
        return value

    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 WhatsAppMessage 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 phone
        if self.phone:
            _dict['phone'] = self.phone.to_dict()
        # override the default output from pydantic by calling `to_dict()` of template
        if self.template:
            _dict['template'] = self.template.to_dict()
        # override the default output from pydantic by calling `to_dict()` of alternative_channel
        if self.alternative_channel:
            _dict['alternative_channel'] = self.alternative_channel.to_dict()
        # set to None if template (nullable) is None
        # and model_fields_set contains the field
        if self.template is None and "template" in self.model_fields_set:
            _dict['template'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "phone": Phone.from_dict(obj["phone"]) if obj.get("phone") is not None else None,
            "sender": obj.get("sender"),
            "type": obj.get("type"),
            "template": WhatsAppMessageTemplate.from_dict(obj["template"]) if obj.get("template") is not None else None,
            "alternative_channel": WhatsAppMessageAlternativeChannel.from_dict(obj["alternative_channel"]) if obj.get("alternative_channel") is not None else None,
            "callback_url": obj.get("callback_url"),
            "add_to_contact_book": obj.get("add_to_contact_book") if obj.get("add_to_contact_book") is not None else True,
            "check_stop_list": obj.get("check_stop_list") if obj.get("check_stop_list") is not None else True
        })
        return _obj


