# 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 date, datetime
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from voucherify.models.customer_loyalty import CustomerLoyalty
from voucherify.models.customer_referrals import CustomerReferrals
from voucherify.models.customer_summary import CustomerSummary
from voucherify.models.customers_create_response_body_address import CustomersCreateResponseBodyAddress
from voucherify.models.customers_create_response_body_assets import CustomersCreateResponseBodyAssets
from typing import Optional, Set
from typing_extensions import Self

class CustomersCreateResponseBody(BaseModel):
    """
    Response body for **POST** `v1/customers`.
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="The ID of an existing customer that will be linked to redemption in this request.")
    source_id: Optional[StrictStr] = Field(default=None, description="A unique identifier of the customer who validates a voucher. It can be a customer ID or email from a CRM system, database, or a third-party service. If you also pass a customer ID (unique ID assigned by Voucherify), the source ID will be ignored.")
    summary: Optional[CustomerSummary] = None
    loyalty: Optional[CustomerLoyalty] = None
    referrals: Optional[CustomerReferrals] = None
    system_metadata: Optional[Dict[str, Any]] = Field(default=None, description="Object used to store system metadata information.")
    created_at: Optional[datetime] = Field(default=None, description="Timestamp representing the date and time when the customer was created. The value is shown in the ISO 8601 format.")
    updated_at: Optional[datetime] = Field(default=None, description="Timestamp representing the date and time when the customer was updated. The value is shown in the ISO 8601 format.")
    assets: Optional[CustomersCreateResponseBodyAssets] = None
    object: Optional[StrictStr] = Field(default='customer', description="The type of the object represented by JSON.")
    name: Optional[StrictStr] = Field(default=None, description="Customer's first and last name.")
    description: Optional[StrictStr] = Field(default=None, description="An arbitrary string that you can attach to a customer object.")
    email: Optional[StrictStr] = Field(default=None, description="Customer's email address.")
    phone: Optional[StrictStr] = Field(default=None, description="Customer's phone number. This parameter is mandatory when you try to send out codes to customers via an SMS channel.")
    birthday: Optional[date] = Field(default=None, description="`Deprecated`. ~~Customer's birthdate; format YYYY-MM-DD~~.")
    birthdate: Optional[date] = Field(default=None, description="Customer's birthdate; format YYYY-MM-DD.")
    address: Optional[CustomersCreateResponseBodyAddress] = None
    metadata: Optional[Dict[str, Any]] = Field(default=None, description="A set of custom key/value pairs that you can attach to a customer. The metadata object stores all custom attributes assigned to the customer. It can be useful for storing additional information about the customer in a structured format. This metadata can be used for validating whether the customer qualifies for a discount or it can be used in building customer segments.")
    __properties: ClassVar[List[str]] = ["id", "source_id", "summary", "loyalty", "referrals", "system_metadata", "created_at", "updated_at", "assets", "object", "name", "description", "email", "phone", "birthday", "birthdate", "address", "metadata"]

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

        if value not in set(['customer']):
            raise ValueError("must be one of enum values ('customer')")
        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 CustomersCreateResponseBody 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 summary
        if self.summary:
            _dict['summary'] = self.summary.to_dict()
        # override the default output from pydantic by calling `to_dict()` of loyalty
        if self.loyalty:
            _dict['loyalty'] = self.loyalty.to_dict()
        # override the default output from pydantic by calling `to_dict()` of referrals
        if self.referrals:
            _dict['referrals'] = self.referrals.to_dict()
        # override the default output from pydantic by calling `to_dict()` of assets
        if self.assets:
            _dict['assets'] = self.assets.to_dict()
        # override the default output from pydantic by calling `to_dict()` of address
        if self.address:
            _dict['address'] = self.address.to_dict()
        # 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 source_id (nullable) is None
        # and model_fields_set contains the field
        if self.source_id is None and "source_id" in self.model_fields_set:
            _dict['source_id'] = None

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "source_id": obj.get("source_id"),
            "summary": CustomerSummary.from_dict(obj["summary"]) if obj.get("summary") is not None else None,
            "loyalty": CustomerLoyalty.from_dict(obj["loyalty"]) if obj.get("loyalty") is not None else None,
            "referrals": CustomerReferrals.from_dict(obj["referrals"]) if obj.get("referrals") is not None else None,
            "system_metadata": obj.get("system_metadata"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "assets": CustomersCreateResponseBodyAssets.from_dict(obj["assets"]) if obj.get("assets") is not None else None,
            "object": obj.get("object") if obj.get("object") is not None else 'customer',
            "name": obj.get("name"),
            "description": obj.get("description"),
            "email": obj.get("email"),
            "phone": obj.get("phone"),
            "birthday": obj.get("birthday"),
            "birthdate": obj.get("birthdate"),
            "address": CustomersCreateResponseBodyAddress.from_dict(obj["address"]) if obj.get("address") is not None else None,
            "metadata": obj.get("metadata")
        })
        return _obj


