# 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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from bsg_api.models.message_api_schema_alternative_channels import MessageApiSchemaAlternativeChannels
from bsg_api.models.message_price_object import MessagePriceObject
from bsg_api.models.message_source import MessageSource
from bsg_api.models.message_status import MessageStatus
from bsg_api.models.message_type import MessageType
from bsg_api.models.options import Options
from typing import Optional, Set
from typing_extensions import Self

class MessageApiSchema(BaseModel):
    """
    MessageApiSchema
    """ # noqa: E501
    id: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=None, description="Message ID – a unique identifier automatically generated on the Platform when the message is created")
    campaign_id: Optional[StrictInt] = Field(default=None, description="campaign unique identifier")
    reference_id: Optional[StrictStr] = Field(default=None, description="external unique ID. String up to 32 characters containing only alpha numeric characters.  **Please note:** messages with duplicate reference_id will be rejected")
    type: Optional[MessageType] = None
    source: Optional[MessageSource] = None
    text: Optional[StrictStr] = Field(default=None, description="Message text to send")
    phone: Optional[Annotated[int, Field(le=999999999999999, strict=True, ge=100000000)]] = Field(default=None, description="Phone number without leading plus, just digits")
    validity: Optional[Annotated[int, Field(le=72, strict=True, ge=1)]] = Field(default=72, description="validity time in hours. The default is 72 hours. Integer from 1 to 72")
    status: Optional[MessageStatus] = None
    amount: Optional[MessagePriceObject] = None
    sender: Optional[StrictStr] = Field(default=None, description="Sender name.   Up to 11 Latin letters or digits, up to 15 – only digits. To setup senders visit the [account](https://app.bsg.world/sms/senders) or use [sender api](#tag/Senders)")
    created_at: Optional[datetime] = Field(default=None, description="Date when the item was created in the system ― set by the system automatically. Display format ― Y-m-d H:i:s")
    sent_at: Optional[datetime] = Field(default=None, description="Date and time of sending the message")
    delivered_at: Optional[datetime] = Field(default=None, description="Date and time of receipt of the delivery report response")
    country: Optional[StrictStr] = Field(default=None, description="Country code according to ISO 3166-1 alpha-2 standard")
    parts: Optional[StrictInt] = None
    rcs_options: Optional[Options] = None
    alternative_channels: Optional[MessageApiSchemaAlternativeChannels] = None
    __properties: ClassVar[List[str]] = ["id", "campaign_id", "reference_id", "type", "source", "text", "phone", "validity", "status", "amount", "sender", "created_at", "sent_at", "delivered_at", "country", "parts", "rcs_options", "alternative_channels"]

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "campaign_id": obj.get("campaign_id"),
            "reference_id": obj.get("reference_id"),
            "type": obj.get("type"),
            "source": obj.get("source"),
            "text": obj.get("text"),
            "phone": obj.get("phone"),
            "validity": obj.get("validity") if obj.get("validity") is not None else 72,
            "status": obj.get("status"),
            "amount": MessagePriceObject.from_dict(obj["amount"]) if obj.get("amount") is not None else None,
            "sender": obj.get("sender"),
            "created_at": obj.get("created_at"),
            "sent_at": obj.get("sent_at"),
            "delivered_at": obj.get("delivered_at"),
            "country": obj.get("country"),
            "parts": obj.get("parts"),
            "rcs_options": Options.from_dict(obj["rcs_options"]) if obj.get("rcs_options") is not None else None,
            "alternative_channels": MessageApiSchemaAlternativeChannels.from_dict(obj["alternative_channels"]) if obj.get("alternative_channels") is not None else None
        })
        return _obj


