# coding: utf-8

"""
    Elastic Email REST API

    This API is based on the REST API architecture, allowing the user to easily manage their data with this resource-based approach.    Every API call is established on which specific request type (GET, POST, PUT, DELETE) will be used.    The API has a limit of 20 concurrent connections and a hard timeout of 600 seconds per request.    To start using this API, you will need your Access Token (available <a target=\"_blank\" href=\"https://app.elasticemail.com/marketing/settings/new/manage-api\">here</a>). Remember to keep it safe. Required access levels are listed in the given request’s description.    Downloadable library clients can be found in our Github repository <a target=\"_blank\" href=\"https://github.com/ElasticEmail?tab=repositories&q=%22rest+api%22+in%3Areadme\">here</a>

    The version of the OpenAPI document: 4.0.0
    Contact: support@elasticemail.com
    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, StrictFloat, StrictInt
from typing import Any, ClassVar, Dict, List, Optional, Union
from ElasticEmail.models.delivery_optimization_type import DeliveryOptimizationType
from ElasticEmail.models.split_options import SplitOptions
from typing import Optional, Set
from typing_extensions import Self

class CampaignOptions(BaseModel):
    """
    Different send options for a Campaign
    """ # noqa: E501
    delivery_optimization: Optional[DeliveryOptimizationType] = Field(default=None, alias="DeliveryOptimization")
    track_opens: Optional[StrictBool] = Field(default=None, description="Should the opens be tracked? If no value has been provided, Account's default setting will be used.", alias="TrackOpens")
    track_clicks: Optional[StrictBool] = Field(default=None, description="Should the clicks be tracked? If no value has been provided, Account's default setting will be used.", alias="TrackClicks")
    schedule_for: Optional[datetime] = Field(default=None, description="Date when this Campaign is scheduled to be sent on", alias="ScheduleFor")
    trigger_frequency: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="How often (in minutes) to send the campaign", alias="TriggerFrequency")
    trigger_count: Optional[StrictInt] = Field(default=None, description="How many times send the campaign", alias="TriggerCount")
    split_options: Optional[SplitOptions] = Field(default=None, alias="SplitOptions")
    __properties: ClassVar[List[str]] = ["DeliveryOptimization", "TrackOpens", "TrackClicks", "ScheduleFor", "TriggerFrequency", "TriggerCount", "SplitOptions"]

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "DeliveryOptimization": obj.get("DeliveryOptimization"),
            "TrackOpens": obj.get("TrackOpens"),
            "TrackClicks": obj.get("TrackClicks"),
            "ScheduleFor": obj.get("ScheduleFor"),
            "TriggerFrequency": obj.get("TriggerFrequency"),
            "TriggerCount": obj.get("TriggerCount"),
            "SplitOptions": SplitOptions.from_dict(obj["SplitOptions"]) if obj.get("SplitOptions") is not None else None
        })
        return _obj


