# 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
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from bsg_api.models.alternative_channel import AlternativeChannel
from bsg_api.models.options import Options
from bsg_api.models.phone import Phone
from typing import Optional, Set
from typing_extensions import Self

class RcsMessage(BaseModel):
    """
    RcsMessage
    """ # noqa: E501
    phone: Phone
    sender: Annotated[str, Field(min_length=1, strict=True, max_length=40)]
    options: Options
    alternative_channel: Optional[AlternativeChannel] = 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.")
    tariff_code: Optional[Annotated[int, Field(strict=True, ge=0)]] = None
    validity_seconds: Optional[Annotated[int, Field(le=86400, strict=True, ge=30)]] = Field(default=None, description="Validity period in seconds. If not set, field \"validity\" is used")
    validity: Optional[Annotated[int, Field(le=72, strict=True, ge=1)]] = Field(default=72, description="Validity period in hours")
    add_to_contact_book: Optional[StrictBool] = True
    check_stop_list: Optional[StrictBool] = True
    __properties: ClassVar[List[str]] = ["phone", "sender", "options", "alternative_channel", "callback_url", "tariff_code", "validity_seconds", "validity", "add_to_contact_book", "check_stop_list"]

    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 RcsMessage 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 options
        if self.options:
            _dict['options'] = self.options.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 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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of RcsMessage 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"),
            "options": Options.from_dict(obj["options"]) if obj.get("options") is not None else None,
            "alternative_channel": AlternativeChannel.from_dict(obj["alternative_channel"]) if obj.get("alternative_channel") is not None else None,
            "callback_url": obj.get("callback_url"),
            "tariff_code": obj.get("tariff_code"),
            "validity_seconds": obj.get("validity_seconds"),
            "validity": obj.get("validity") if obj.get("validity") is not None else 72,
            "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


