# 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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from bsg_api.models.campaign_status import CampaignStatus
from bsg_api.models.message_type import MessageType
from bsg_api.models.statistics_short import StatisticsShort
from typing import Optional, Set
from typing_extensions import Self

class CampaignSchema(BaseModel):
    """
    Main campaign properties
    """ # noqa: E501
    id: Optional[StrictInt] = Field(default=None, description="campaign unique identifier")
    name: Optional[StrictStr] = Field(default=None, description="campaign auto generated name")
    sender: Optional[StrictStr] = Field(default=None, 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)")
    status: Optional[CampaignStatus] = None
    message_type: Optional[MessageType] = None
    start_at: Optional[datetime] = Field(default=None, description="Start sending the messages at")
    real_start_at: Optional[datetime] = Field(default=None, description="Real time when sending the messages starts")
    finished_at: Optional[datetime] = None
    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")
    statistics: Optional[StatisticsShort] = None
    calculated_price: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="estimate campaign cost  **Please note:** price defined only as the response to create campaign or calculate price requests")
    currency: Optional[StrictStr] = Field(default=None, description="The currency code of the account. Specified according to the ISO-4217 standard")
    __properties: ClassVar[List[str]] = ["id", "name", "sender", "status", "message_type", "start_at", "real_start_at", "finished_at", "created_at", "statistics", "calculated_price", "currency"]

    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 CampaignSchema 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 statistics
        if self.statistics:
            _dict['statistics'] = self.statistics.to_dict()
        # set to None if real_start_at (nullable) is None
        # and model_fields_set contains the field
        if self.real_start_at is None and "real_start_at" in self.model_fields_set:
            _dict['real_start_at'] = None

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CampaignSchema 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"),
            "name": obj.get("name"),
            "sender": obj.get("sender"),
            "status": obj.get("status"),
            "message_type": obj.get("message_type"),
            "start_at": obj.get("start_at"),
            "real_start_at": obj.get("real_start_at"),
            "finished_at": obj.get("finished_at"),
            "created_at": obj.get("created_at"),
            "statistics": StatisticsShort.from_dict(obj["statistics"]) if obj.get("statistics") is not None else None,
            "calculated_price": obj.get("calculated_price"),
            "currency": obj.get("currency")
        })
        return _obj


