# 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.member_activity_data_redemption_reward_customer import MemberActivityDataRedemptionRewardCustomer
from voucherify.models.member_activity_data_redemption_reward_parameters import MemberActivityDataRedemptionRewardParameters
from voucherify.models.member_activity_data_redemption_reward_product import MemberActivityDataRedemptionRewardProduct
from voucherify.models.member_activity_data_redemption_reward_sku import MemberActivityDataRedemptionRewardSku
from voucherify.models.member_activity_data_redemption_reward_voucher import MemberActivityDataRedemptionRewardVoucher
from typing import Optional, Set
from typing_extensions import Self

class MemberActivityDataRedemptionReward(BaseModel):
    """
    MemberActivityDataRedemptionReward
    """ # noqa: E501
    customer: Optional[MemberActivityDataRedemptionRewardCustomer] = None
    assignment_id: Optional[StrictStr] = Field(default=None, description="Unique reward assignment ID assigned by Voucherify.")
    voucher: Optional[MemberActivityDataRedemptionRewardVoucher] = None
    product: Optional[MemberActivityDataRedemptionRewardProduct] = None
    sku: Optional[MemberActivityDataRedemptionRewardSku] = None
    loyalty_tier_id: Optional[StrictStr] = Field(default=None, description="Unique loyalty tier ID assigned by Voucherify.")
    id: Optional[StrictStr] = None
    object: Optional[StrictStr] = 'reward'
    name: Optional[StrictStr] = None
    created_at: Optional[StrictStr] = None
    updated_at: Optional[StrictStr] = None
    parameters: Optional[MemberActivityDataRedemptionRewardParameters] = None
    metadata: Optional[Dict[str, Any]] = Field(default=None, description="A set of custom key/value pairs that you can attach to a reward. The metadata object stores all custom attributes assigned to the reward.")
    type: Optional[StrictStr] = Field(default=None, description="Reward type.")
    __properties: ClassVar[List[str]] = ["customer", "assignment_id", "voucher", "product", "sku", "loyalty_tier_id", "id", "object", "name", "created_at", "updated_at", "parameters", "metadata", "type"]

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

        if value not in set(['reward']):
            raise ValueError("must be one of enum values ('reward')")
        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(['CAMPAIGN', 'COIN', 'MATERIAL']):
            raise ValueError("must be one of enum values ('CAMPAIGN', 'COIN', 'MATERIAL')")
        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 MemberActivityDataRedemptionReward 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 customer
        if self.customer:
            _dict['customer'] = self.customer.to_dict()
        # override the default output from pydantic by calling `to_dict()` of voucher
        if self.voucher:
            _dict['voucher'] = self.voucher.to_dict()
        # override the default output from pydantic by calling `to_dict()` of product
        if self.product:
            _dict['product'] = self.product.to_dict()
        # override the default output from pydantic by calling `to_dict()` of sku
        if self.sku:
            _dict['sku'] = self.sku.to_dict()
        # override the default output from pydantic by calling `to_dict()` of parameters
        if self.parameters:
            _dict['parameters'] = self.parameters.to_dict()
        # set to None if customer (nullable) is None
        # and model_fields_set contains the field
        if self.customer is None and "customer" in self.model_fields_set:
            _dict['customer'] = None

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "customer": MemberActivityDataRedemptionRewardCustomer.from_dict(obj["customer"]) if obj.get("customer") is not None else None,
            "assignment_id": obj.get("assignment_id"),
            "voucher": MemberActivityDataRedemptionRewardVoucher.from_dict(obj["voucher"]) if obj.get("voucher") is not None else None,
            "product": MemberActivityDataRedemptionRewardProduct.from_dict(obj["product"]) if obj.get("product") is not None else None,
            "sku": MemberActivityDataRedemptionRewardSku.from_dict(obj["sku"]) if obj.get("sku") is not None else None,
            "loyalty_tier_id": obj.get("loyalty_tier_id"),
            "id": obj.get("id"),
            "object": obj.get("object") if obj.get("object") is not None else 'reward',
            "name": obj.get("name"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "parameters": MemberActivityDataRedemptionRewardParameters.from_dict(obj["parameters"]) if obj.get("parameters") is not None else None,
            "metadata": obj.get("metadata"),
            "type": obj.get("type")
        })
        return _obj


