# 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, StrictInt, StrictStr, field_validator
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.phone import Phone
from typing import Optional, Set
from typing_extensions import Self

class SendViberCampaign(BaseModel):
    """
    SendViberCampaign
    """ # noqa: E501
    phones: Annotated[List[Phone], Field(min_length=1, max_length=5000)] = Field(description="The list of objects containing information about the mobile phone number (number) and (reference_id) to send a message to")
    sender: StrictStr = Field(description="Sender’s name: from 3 to 11 characters for the sender’s alphanumeric name (Latin letters, symbols, numbers, spaces); 3 to 15 characters for the sender’s numeric name. To setup senders visit the [account](https://app.bsg.world/sms/senders)")
    text: Annotated[str, Field(min_length=1, strict=True, max_length=1000)]
    image_url: Optional[Annotated[str, Field(strict=True, max_length=255)]] = None
    button_caption: Optional[Annotated[str, Field(strict=True, max_length=20)]] = None
    link_url: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="Required if button_caption is set")
    start_at: Optional[datetime] = Field(default=None, description="Start sending the messages at")
    tariff_code: Optional[StrictInt] = Field(default=None, description="Tariff code null by default. Your can pass specified one if you have several. For more information please visit the [account prices](https://app.bsg.world/prices/sms)")
    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")
    alternative_channel: Optional[AlternativeChannel] = None
    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", "text", "image_url", "button_caption", "link_url", "start_at", "tariff_code", "validity", "alternative_channel", "add_to_contact_book", "check_stop_list"]

    @field_validator('image_url')
    def image_url_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^(http|https):\/\/([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+(:(\d+))?([-_\/A-Z0-9?=&]*)?(\.jpg|\.png|\.tiff|\.jpeg|\.gif|\.bmp){1}$", value ,re.IGNORECASE):
            raise ValueError(r"must validate the regular expression /^(http|https):\/\/([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+(:(\d+))?([-_\/A-Z0-9?=&]*)?(\.jpg|\.png|\.tiff|\.jpeg|\.gif|\.bmp){1}$/iD")
        return value

    @field_validator('link_url')
    def link_url_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^(https?:\/\/)?([\p{L}\d\.-]+)\.([\p{L}\.]{2,50})([\/\w \.-]*)*\/?", value ,re.IGNORECASE ,re.UNICODE):
            raise ValueError(r"must validate the regular expression /^(https?:\/\/)?([\p{L}\d\.-]+)\.([\p{L}\.]{2,50})([\/\w \.-]*)*\/?/iu")
        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 SendViberCampaign 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 alternative_channel
        if self.alternative_channel:
            _dict['alternative_channel'] = self.alternative_channel.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of SendViberCampaign 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"),
            "text": obj.get("text"),
            "image_url": obj.get("image_url"),
            "button_caption": obj.get("button_caption"),
            "link_url": obj.get("link_url"),
            "start_at": obj.get("start_at"),
            "tariff_code": obj.get("tariff_code"),
            "validity": obj.get("validity") if obj.get("validity") is not None else 72,
            "alternative_channel": AlternativeChannel.from_dict(obj["alternative_channel"]) if obj.get("alternative_channel") is not None else None,
            "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


