# 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 pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from voucherify.models.loyalty_tiers_expiration_all_expiration_date import LoyaltyTiersExpirationAllExpirationDate
from voucherify.models.loyalty_tiers_expiration_all_start_date import LoyaltyTiersExpirationAllStartDate
from typing import Optional, Set
from typing_extensions import Self

class LoyaltyTiersExpirationAll(BaseModel):
    """
    Defines the Loyalty Tiers Expiration.
    """ # noqa: E501
    qualification_type: Optional[StrictStr] = Field(default=None, description="Tier qualification.     `BALANCE`: Points balance is based on the customer's current points balance. Customers qualify for the tier if their points balance is in the points range of the tier.   `POINTS_IN_PERIOD`: A customer qualifies for the tier only if the sum of the accumulated points in a **defined time interval** reaches the tier threshold.")
    qualification_period: Optional[StrictStr] = Field(default=None, description="Customers can qualify for the tier if they collected enough points in a given time period. So, in addition to the customer having to reach a points range, they also need to have collected the points within a set time period.      | **Period** | **Definition** | |:---|:---| | **Calendar Month** | Points collected in one calendar month<br>January, February, March, etc. | | **Calendar Quarter** | Points collected in the quarter<br>- January - March<br>- April - June<br>- July - September<br>- October - December | | **Calendar Half-year** | Points collected in the half-year<br>- January - June<br>- July - December | | **Calendar Year** | Points collected in one calendar year<br>January - December |")
    start_date: Optional[LoyaltyTiersExpirationAllStartDate] = None
    expiration_date: Optional[LoyaltyTiersExpirationAllExpirationDate] = None
    __properties: ClassVar[List[str]] = ["qualification_type", "qualification_period", "start_date", "expiration_date"]

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

        if value not in set(['BALANCE', 'POINTS_IN_PERIOD']):
            raise ValueError("must be one of enum values ('BALANCE', 'POINTS_IN_PERIOD')")
        return value

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

        if value not in set(['MONTH', 'QUARTER', 'HALF_YEAR', 'YEAR']):
            raise ValueError("must be one of enum values ('MONTH', 'QUARTER', 'HALF_YEAR', 'YEAR')")
        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 LoyaltyTiersExpirationAll 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 start_date
        if self.start_date:
            _dict['start_date'] = self.start_date.to_dict()
        # override the default output from pydantic by calling `to_dict()` of expiration_date
        if self.expiration_date:
            _dict['expiration_date'] = self.expiration_date.to_dict()
        # set to None if qualification_type (nullable) is None
        # and model_fields_set contains the field
        if self.qualification_type is None and "qualification_type" in self.model_fields_set:
            _dict['qualification_type'] = None

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

        # 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

        return _dict

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

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

        _obj = cls.model_validate({
            "qualification_type": obj.get("qualification_type"),
            "qualification_period": obj.get("qualification_period"),
            "start_date": LoyaltyTiersExpirationAllStartDate.from_dict(obj["start_date"]) if obj.get("start_date") is not None else None,
            "expiration_date": LoyaltyTiersExpirationAllExpirationDate.from_dict(obj["expiration_date"]) if obj.get("expiration_date") is not None else None
        })
        return _obj


