# coding: utf-8

"""
    BoxBilling

    A comprehensive usage-based billing platform API. Manage customers, plans, subscriptions, invoices, payments, wallets, coupons, credit notes, taxes, webhooks, and more.

    The version of the OpenAPI document: 0.6.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from uuid import UUID
from bxb.models.initial_granted_credits import InitialGrantedCredits
from bxb.models.rate_amount import RateAmount
from typing import Optional, Set
from typing_extensions import Self

class WalletCreate(BaseModel):
    """
    WalletCreate
    """ # noqa: E501
    customer_id: UUID
    name: Optional[Annotated[str, Field(strict=True, max_length=255)]] = None
    code: Optional[Annotated[str, Field(strict=True, max_length=255)]] = None
    rate_amount: Optional[RateAmount] = None
    currency: Optional[Annotated[str, Field(min_length=3, strict=True, max_length=3)]] = 'USD'
    expiration_at: Optional[datetime] = None
    priority: Optional[Annotated[int, Field(le=50, strict=True, ge=1)]] = 1
    initial_granted_credits: Optional[InitialGrantedCredits] = None
    __properties: ClassVar[List[str]] = ["customer_id", "name", "code", "rate_amount", "currency", "expiration_at", "priority", "initial_granted_credits"]

    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 WalletCreate 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 rate_amount
        if self.rate_amount:
            _dict['rate_amount'] = self.rate_amount.to_dict()
        # override the default output from pydantic by calling `to_dict()` of initial_granted_credits
        if self.initial_granted_credits:
            _dict['initial_granted_credits'] = self.initial_granted_credits.to_dict()
        # 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 code (nullable) is None
        # and model_fields_set contains the field
        if self.code is None and "code" in self.model_fields_set:
            _dict['code'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "customer_id": obj.get("customer_id"),
            "name": obj.get("name"),
            "code": obj.get("code"),
            "rate_amount": RateAmount.from_dict(obj["rate_amount"]) if obj.get("rate_amount") is not None else None,
            "currency": obj.get("currency") if obj.get("currency") is not None else 'USD',
            "expiration_at": obj.get("expiration_at"),
            "priority": obj.get("priority") if obj.get("priority") is not None else 1,
            "initial_granted_credits": InitialGrantedCredits.from_dict(obj["initial_granted_credits"]) if obj.get("initial_granted_credits") is not None else None
        })
        return _obj


