# coding: utf-8

"""
    Voucherify API

    Voucherify promotion engine REST API. Please see https://docs.voucherify.io/docs for more details.

    The version of the OpenAPI document: v2018-08-01
    Contact: support@voucherify.io
    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 voucherify.models.access_settings import AccessSettings
from voucherify.models.campaigns_update_request_body_options import CampaignsUpdateRequestBodyOptions
from voucherify.models.discount import Discount
from voucherify.models.gift import Gift
from voucherify.models.loyalty_tiers_expiration_all import LoyaltyTiersExpirationAll
from voucherify.models.referral_program import ReferralProgram
from voucherify.models.validity_hours import ValidityHours
from voucherify.models.validity_timeframe import ValidityTimeframe
from typing import Optional, Set
from typing_extensions import Self

class CampaignsUpdateRequestBody(BaseModel):
    """
    CampaignsUpdateRequestBody
    """ # noqa: E501
    start_date: Optional[datetime] = Field(default=None, description="Activation timestamp defines when the campaign starts to be active in ISO 8601 format. Campaign is *inactive before* this date. ")
    expiration_date: Optional[datetime] = Field(default=None, description="Expiration timestamp defines when the campaign expires in ISO 8601 format.  Campaign is *inactive after* this date.")
    validity_timeframe: Optional[ValidityTimeframe] = None
    validity_day_of_week: Optional[List[StrictInt]] = Field(default=None, description="Integer array corresponding to the particular days of the week in which the voucher is valid.  - `0` Sunday - `1` Monday - `2` Tuesday - `3` Wednesday - `4` Thursday - `5` Friday - `6` Saturday")
    validity_hours: Optional[ValidityHours] = None
    description: Optional[StrictStr] = Field(default=None, description="An optional field to keep any extra textual information about the campaign such as a campaign description and details.")
    category: Optional[StrictStr] = Field(default=None, description="The category assigned to the campaign. Either pass this parameter OR the `category_id`.")
    metadata: Optional[Dict[str, Any]] = Field(default=None, description="The metadata object stores all custom attributes assigned to the campaign. A set of key/value pairs that you can attach to a campaign object. It can be useful for storing additional information about the campaign in a structured format.")
    unset_metadata_fields: Optional[List[StrictStr]] = Field(default=None, description="Determine which metadata should be removed from campaign.")
    category_id: Optional[StrictStr] = Field(default=None, description="Unique category ID that this campaign belongs to. Either pass this parameter OR the `category`.")
    access_settings: Optional[AccessSettings] = None
    activity_duration_after_publishing: Optional[StrictStr] = Field(default=None, description="Defines the amount of time the vouchers will be active after publishing. The value is shown in the ISO 8601 format. For example, a voucher with the value of P24D will be valid for a duration of 24 days.")
    join_once: Optional[StrictBool] = Field(default=None, description="If this value is set to `true`, customers will be able to join the campaign only once. It is always `false` for generic (standalone) vouchers campaigns and it cannot be changed in them. It is always `true` for loyalty campaigns and it cannot be changed in them.")
    auto_join: Optional[StrictBool] = Field(default=None, description="Indicates whether customers will be able to auto-join a loyalty campaign if any earning rule is fulfilled.")
    type: Optional[StrictStr] = Field(default=None, description="Defines whether the campaign can be updated with new vouchers after campaign creation.  - `AUTO_UPDATE`: By choosing the auto update option you will create a campaign that can be enhanced by new vouchers after the time of creation (e.g. by publish vouchers method). -  `STATIC`: vouchers need to be manually published.  If the `type` of the campaign is `STANDALONE`, the type cannot be changed. Also, the `type` cannot be changed to `STANDALONE`.")
    discount: Optional[Discount] = None
    referral_program: Optional[ReferralProgram] = None
    gift: Optional[Gift] = None
    loyalty_tiers_expiration: Optional[LoyaltyTiersExpirationAll] = None
    options: Optional[CampaignsUpdateRequestBodyOptions] = None
    __properties: ClassVar[List[str]] = ["start_date", "expiration_date", "validity_timeframe", "validity_day_of_week", "validity_hours", "description", "category", "metadata", "unset_metadata_fields", "category_id", "access_settings", "activity_duration_after_publishing", "join_once", "auto_join", "type", "discount", "referral_program", "gift", "loyalty_tiers_expiration", "options"]

    @field_validator('validity_day_of_week')
    def validity_day_of_week_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        for i in value:
            if i not in set([0, 1, 2, 3, 4, 5, 6]):
                raise ValueError("each list item must be one of (0, 1, 2, 3, 4, 5, 6)")
        return value

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['AUTO_UPDATE', 'STATIC']):
            raise ValueError("must be one of enum values ('AUTO_UPDATE', 'STATIC')")
        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 CampaignsUpdateRequestBody 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 validity_timeframe
        if self.validity_timeframe:
            _dict['validity_timeframe'] = self.validity_timeframe.to_dict()
        # override the default output from pydantic by calling `to_dict()` of validity_hours
        if self.validity_hours:
            _dict['validity_hours'] = self.validity_hours.to_dict()
        # override the default output from pydantic by calling `to_dict()` of access_settings
        if self.access_settings:
            _dict['access_settings'] = self.access_settings.to_dict()
        # override the default output from pydantic by calling `to_dict()` of discount
        if self.discount:
            _dict['discount'] = self.discount.to_dict()
        # override the default output from pydantic by calling `to_dict()` of referral_program
        if self.referral_program:
            _dict['referral_program'] = self.referral_program.to_dict()
        # override the default output from pydantic by calling `to_dict()` of gift
        if self.gift:
            _dict['gift'] = self.gift.to_dict()
        # override the default output from pydantic by calling `to_dict()` of loyalty_tiers_expiration
        if self.loyalty_tiers_expiration:
            _dict['loyalty_tiers_expiration'] = self.loyalty_tiers_expiration.to_dict()
        # override the default output from pydantic by calling `to_dict()` of options
        if self.options:
            _dict['options'] = self.options.to_dict()
        # set to None if start_date (nullable) is None
        # and model_fields_set contains the field
        if self.start_date is None and "start_date" in self.model_fields_set:
            _dict['start_date'] = None

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "start_date": obj.get("start_date"),
            "expiration_date": obj.get("expiration_date"),
            "validity_timeframe": ValidityTimeframe.from_dict(obj["validity_timeframe"]) if obj.get("validity_timeframe") is not None else None,
            "validity_day_of_week": obj.get("validity_day_of_week"),
            "validity_hours": ValidityHours.from_dict(obj["validity_hours"]) if obj.get("validity_hours") is not None else None,
            "description": obj.get("description"),
            "category": obj.get("category"),
            "metadata": obj.get("metadata"),
            "unset_metadata_fields": obj.get("unset_metadata_fields"),
            "category_id": obj.get("category_id"),
            "access_settings": AccessSettings.from_dict(obj["access_settings"]) if obj.get("access_settings") is not None else None,
            "activity_duration_after_publishing": obj.get("activity_duration_after_publishing"),
            "join_once": obj.get("join_once"),
            "auto_join": obj.get("auto_join"),
            "type": obj.get("type"),
            "discount": Discount.from_dict(obj["discount"]) if obj.get("discount") is not None else None,
            "referral_program": ReferralProgram.from_dict(obj["referral_program"]) if obj.get("referral_program") is not None else None,
            "gift": Gift.from_dict(obj["gift"]) if obj.get("gift") is not None else None,
            "loyalty_tiers_expiration": LoyaltyTiersExpirationAll.from_dict(obj["loyalty_tiers_expiration"]) if obj.get("loyalty_tiers_expiration") is not None else None,
            "options": CampaignsUpdateRequestBodyOptions.from_dict(obj["options"]) if obj.get("options") is not None else None
        })
        return _obj


