# 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
from typing import Any, ClassVar, Dict, List, Optional
from voucherify.models.loyalty_card_transaction_details_balance import LoyaltyCardTransactionDetailsBalance
from voucherify.models.loyalty_card_transaction_details_custom_event import LoyaltyCardTransactionDetailsCustomEvent
from voucherify.models.loyalty_card_transaction_details_earning_rule import LoyaltyCardTransactionDetailsEarningRule
from voucherify.models.loyalty_card_transaction_details_event import LoyaltyCardTransactionDetailsEvent
from voucherify.models.loyalty_card_transaction_details_event_schema import LoyaltyCardTransactionDetailsEventSchema
from voucherify.models.loyalty_card_transaction_details_loyalty_tier import LoyaltyCardTransactionDetailsLoyaltyTier
from voucherify.models.loyalty_card_transaction_details_order import LoyaltyCardTransactionDetailsOrder
from voucherify.models.loyalty_card_transaction_details_redemption import LoyaltyCardTransactionDetailsRedemption
from voucherify.models.loyalty_card_transaction_details_reward import LoyaltyCardTransactionDetailsReward
from voucherify.models.loyalty_card_transaction_details_rollback import LoyaltyCardTransactionDetailsRollback
from voucherify.models.loyalty_card_transaction_details_segment import LoyaltyCardTransactionDetailsSegment
from voucherify.models.simple_voucher import SimpleVoucher
from typing import Optional, Set
from typing_extensions import Self

class LoyaltyCardTransactionDetails(BaseModel):
    """
    Contains the detailed information about the transaction.
    """ # noqa: E501
    balance: Optional[LoyaltyCardTransactionDetailsBalance] = None
    order: Optional[LoyaltyCardTransactionDetailsOrder] = None
    event: Optional[LoyaltyCardTransactionDetailsEvent] = None
    earning_rule: Optional[LoyaltyCardTransactionDetailsEarningRule] = None
    segment: Optional[LoyaltyCardTransactionDetailsSegment] = None
    loyalty_tier: Optional[LoyaltyCardTransactionDetailsLoyaltyTier] = None
    redemption: Optional[LoyaltyCardTransactionDetailsRedemption] = None
    rollback: Optional[LoyaltyCardTransactionDetailsRollback] = None
    custom_event: Optional[LoyaltyCardTransactionDetailsCustomEvent] = None
    event_schema: Optional[LoyaltyCardTransactionDetailsEventSchema] = None
    reward: Optional[LoyaltyCardTransactionDetailsReward] = None
    source_voucher: Optional[SimpleVoucher] = None
    destination_voucher: Optional[SimpleVoucher] = None
    __properties: ClassVar[List[str]] = ["balance", "order", "event", "earning_rule", "segment", "loyalty_tier", "redemption", "rollback", "custom_event", "event_schema", "reward", "source_voucher", "destination_voucher"]

    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 LoyaltyCardTransactionDetails 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 balance
        if self.balance:
            _dict['balance'] = self.balance.to_dict()
        # override the default output from pydantic by calling `to_dict()` of order
        if self.order:
            _dict['order'] = self.order.to_dict()
        # override the default output from pydantic by calling `to_dict()` of event
        if self.event:
            _dict['event'] = self.event.to_dict()
        # override the default output from pydantic by calling `to_dict()` of earning_rule
        if self.earning_rule:
            _dict['earning_rule'] = self.earning_rule.to_dict()
        # override the default output from pydantic by calling `to_dict()` of segment
        if self.segment:
            _dict['segment'] = self.segment.to_dict()
        # override the default output from pydantic by calling `to_dict()` of loyalty_tier
        if self.loyalty_tier:
            _dict['loyalty_tier'] = self.loyalty_tier.to_dict()
        # override the default output from pydantic by calling `to_dict()` of redemption
        if self.redemption:
            _dict['redemption'] = self.redemption.to_dict()
        # override the default output from pydantic by calling `to_dict()` of rollback
        if self.rollback:
            _dict['rollback'] = self.rollback.to_dict()
        # override the default output from pydantic by calling `to_dict()` of custom_event
        if self.custom_event:
            _dict['custom_event'] = self.custom_event.to_dict()
        # override the default output from pydantic by calling `to_dict()` of event_schema
        if self.event_schema:
            _dict['event_schema'] = self.event_schema.to_dict()
        # override the default output from pydantic by calling `to_dict()` of reward
        if self.reward:
            _dict['reward'] = self.reward.to_dict()
        # override the default output from pydantic by calling `to_dict()` of source_voucher
        if self.source_voucher:
            _dict['source_voucher'] = self.source_voucher.to_dict()
        # override the default output from pydantic by calling `to_dict()` of destination_voucher
        if self.destination_voucher:
            _dict['destination_voucher'] = self.destination_voucher.to_dict()
        # set to None if order (nullable) is None
        # and model_fields_set contains the field
        if self.order is None and "order" in self.model_fields_set:
            _dict['order'] = None

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "balance": LoyaltyCardTransactionDetailsBalance.from_dict(obj["balance"]) if obj.get("balance") is not None else None,
            "order": LoyaltyCardTransactionDetailsOrder.from_dict(obj["order"]) if obj.get("order") is not None else None,
            "event": LoyaltyCardTransactionDetailsEvent.from_dict(obj["event"]) if obj.get("event") is not None else None,
            "earning_rule": LoyaltyCardTransactionDetailsEarningRule.from_dict(obj["earning_rule"]) if obj.get("earning_rule") is not None else None,
            "segment": LoyaltyCardTransactionDetailsSegment.from_dict(obj["segment"]) if obj.get("segment") is not None else None,
            "loyalty_tier": LoyaltyCardTransactionDetailsLoyaltyTier.from_dict(obj["loyalty_tier"]) if obj.get("loyalty_tier") is not None else None,
            "redemption": LoyaltyCardTransactionDetailsRedemption.from_dict(obj["redemption"]) if obj.get("redemption") is not None else None,
            "rollback": LoyaltyCardTransactionDetailsRollback.from_dict(obj["rollback"]) if obj.get("rollback") is not None else None,
            "custom_event": LoyaltyCardTransactionDetailsCustomEvent.from_dict(obj["custom_event"]) if obj.get("custom_event") is not None else None,
            "event_schema": LoyaltyCardTransactionDetailsEventSchema.from_dict(obj["event_schema"]) if obj.get("event_schema") is not None else None,
            "reward": LoyaltyCardTransactionDetailsReward.from_dict(obj["reward"]) if obj.get("reward") is not None else None,
            "source_voucher": SimpleVoucher.from_dict(obj["source_voucher"]) if obj.get("source_voucher") is not None else None,
            "destination_voucher": SimpleVoucher.from_dict(obj["destination_voucher"]) if obj.get("destination_voucher") is not None else None
        })
        return _obj


