# coding: utf-8

"""
    FlexPrice API

    FlexPrice API Service

    The version of the OpenAPI document: 1.0
    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, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from flexprice.models.dto_alert_config import DtoAlertConfig
from flexprice.models.types_auto_topup_trigger import TypesAutoTopupTrigger
from flexprice.models.types_wallet_config import TypesWalletConfig
from flexprice.models.types_wallet_type import TypesWalletType
from typing import Optional, Set
from typing_extensions import Self

class DtoCreateWalletRequest(BaseModel):
    """
    DtoCreateWalletRequest
    """ # noqa: E501
    alert_config: Optional[DtoAlertConfig] = None
    alert_enabled: Optional[StrictBool] = Field(default=None, description="alert_enabled is the flag to enable alerts for the wallet defaults to true, can be explicitly set to false to disable alerts")
    auto_topup_amount: Optional[Union[StrictFloat, StrictInt]] = None
    auto_topup_min_balance: Optional[Union[StrictFloat, StrictInt]] = None
    auto_topup_trigger: Optional[TypesAutoTopupTrigger] = None
    config: Optional[TypesWalletConfig] = None
    conversion_rate: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="amount in the currency =  number of credits * conversion_rate ex if conversion_rate is 1, then 1 USD = 1 credit ex if conversion_rate is 2, then 1 USD = 0.5 credits ex if conversion_rate is 0.5, then 1 USD = 2 credits")
    currency: StrictStr
    customer_id: Optional[StrictStr] = None
    description: Optional[StrictStr] = None
    external_customer_id: Optional[StrictStr] = Field(default=None, description="external_customer_id is the customer id in the external system")
    initial_credits_expiry_date_utc: Optional[StrictStr] = Field(default=None, description="initial_credits_expiry_date_utc is the expiry date in UTC timezone (optional to set nil means no expiry) ex 2025-01-01 00:00:00 UTC")
    initial_credits_to_load: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="initial_credits_to_load is the number of credits to load to the wallet if not provided, the wallet will be created with 0 balance NOTE: this is not the amount in the currency, but the number of credits")
    initial_credits_to_load_expiry_date: Optional[StrictInt] = Field(default=None, description="initial_credits_to_load_expiry_date YYYYMMDD format in UTC timezone (optional to set nil means no expiry) for ex 20250101 means the credits will expire on 2025-01-01 00:00:00 UTC hence they will be available for use until 2024-12-31 23:59:59 UTC")
    metadata: Optional[Dict[str, StrictStr]] = None
    name: Optional[StrictStr] = None
    wallet_type: Optional[TypesWalletType] = None
    __properties: ClassVar[List[str]] = ["alert_config", "alert_enabled", "auto_topup_amount", "auto_topup_min_balance", "auto_topup_trigger", "config", "conversion_rate", "currency", "customer_id", "description", "external_customer_id", "initial_credits_expiry_date_utc", "initial_credits_to_load", "initial_credits_to_load_expiry_date", "metadata", "name", "wallet_type"]

    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 DtoCreateWalletRequest 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 alert_config
        if self.alert_config:
            _dict['alert_config'] = self.alert_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of config
        if self.config:
            _dict['config'] = self.config.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "alert_config": DtoAlertConfig.from_dict(obj["alert_config"]) if obj.get("alert_config") is not None else None,
            "alert_enabled": obj.get("alert_enabled"),
            "auto_topup_amount": obj.get("auto_topup_amount"),
            "auto_topup_min_balance": obj.get("auto_topup_min_balance"),
            "auto_topup_trigger": obj.get("auto_topup_trigger"),
            "config": TypesWalletConfig.from_dict(obj["config"]) if obj.get("config") is not None else None,
            "conversion_rate": obj.get("conversion_rate"),
            "currency": obj.get("currency"),
            "customer_id": obj.get("customer_id"),
            "description": obj.get("description"),
            "external_customer_id": obj.get("external_customer_id"),
            "initial_credits_expiry_date_utc": obj.get("initial_credits_expiry_date_utc"),
            "initial_credits_to_load": obj.get("initial_credits_to_load"),
            "initial_credits_to_load_expiry_date": obj.get("initial_credits_to_load_expiry_date"),
            "metadata": obj.get("metadata"),
            "name": obj.get("name"),
            "wallet_type": obj.get("wallet_type")
        })
        return _obj


