# 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, 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.send_whats_app_campaign_alternative_channel import SendWhatsAppCampaignAlternativeChannel
from typing import Optional, Set
from typing_extensions import Self

class SendWhatsAppCampaign(BaseModel):
    """
    SendWhatsAppCampaign
    """ # noqa: E501
    phones: Annotated[List[Phone], Field(min_length=1, max_length=5000)] = Field(description="$phones")
    sender: Annotated[str, Field(min_length=1, strict=True, max_length=40)] = Field(description="The name of the agent used to send the whatsapp message")
    type: StrictStr = Field(description="Type of Whatsapp message, only \"template\" now is supported")
    template: Optional[Any] = Field(default=None, description="Required for type \"template\"")
    alternative_channel: Optional[SendWhatsAppCampaignAlternativeChannel] = None
    start_at: Optional[datetime] = Field(default=None, description="Start sending the messages at")
    add_to_contact_book: Optional[StrictBool] = Field(default=True, description="Specifies whether to add the specified phone number of the message recipient to the contact book")
    check_stop_list: Optional[StrictBool] = Field(default=True, description="Check the recipient’s phone number for being in the stop list.  Possible values:    - true – if the number is found in the stop list, do not send the message  - false – ignore the stop list")
    __properties: ClassVar[List[str]] = ["phones", "sender", "type", "template", "alternative_channel", "start_at", "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 SendWhatsAppCampaign 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 each item in phones (list)
        _items = []
        if self.phones:
            for _item_phones in self.phones:
                if _item_phones:
                    _items.append(_item_phones.to_dict())
            _dict['phones'] = _items
        # 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

        return _dict

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

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

        _obj = cls.model_validate({
            "phones": [Phone.from_dict(_item) for _item in obj["phones"]] if obj.get("phones") is not None else None,
            "sender": obj.get("sender"),
            "type": obj.get("type"),
            "template": Template.from_dict(obj["template"]) if obj.get("template") is not None else None,
            "alternative_channel": SendWhatsAppCampaignAlternativeChannel.from_dict(obj["alternative_channel"]) if obj.get("alternative_channel") is not None else None,
            "start_at": obj.get("start_at"),
            "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


