# coding: utf-8

"""
    ibl-data-manager

    API for iblai

    The version of the OpenAPI document: 4.202.1-ai-plus
    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, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from uuid import UUID
from typing import Optional, Set
from typing_extensions import Self

class CreditAccountInfo(BaseModel):
    """
    Credit account information API response (GET).  Display balance (has_credits, account_id, available_credits) and auto-recharge preferences.
    """ # noqa: E501
    has_credits: StrictBool = Field(description="True if the account has any credits (or infinite credits).")
    account_id: UUID = Field(description="The unique identifier of the credit account.")
    available_credits: Annotated[str, Field(strict=True)] = Field(description="The current available credit balance in USD.")
    auto_recharge_threshold_usd: Annotated[str, Field(strict=True)] = Field(description="The balance threshold below which auto-recharge is triggered.")
    auto_recharge_amount_usd: Annotated[str, Field(strict=True)] = Field(description="The amount in USD to recharge when the threshold is reached.")
    auto_recharge_enabled: StrictBool = Field(description="True if auto-recharge is currently enabled for this account.")
    auto_recharge_last_triggered_at: Optional[datetime] = Field(description="The timestamp when auto-recharge was last successfully triggered.")
    platform_key: StrictStr = Field(description="The platform key associated with this account (if applicable).")
    pricing_table: Optional[Any] = Field(description="Stripe pricing table details for topping up credits.")
    free_trial: StrictBool = Field(description="True if the account is on the free trial plan (no paid plan purchased yet).")
    current_plan: Optional[StrictStr] = Field(description="Current plan identifier, e.g. 'free_trial' or Stripe product SKU.")
    previous_plan: Optional[StrictStr] = Field(description="Previous plan before the last purchase.")
    can_use_auto_recharge: StrictBool = Field(description="True if the current plan is not free_trial (paid plans can use auto-recharge).")
    has_payment_method: StrictBool = Field(description="True if the user has a payment method on file (can use manual top-up and auto-recharge).")
    message: StrictStr = Field(description="Message explaining why credits are insufficient (only present when has_credits is False).")
    __properties: ClassVar[List[str]] = ["has_credits", "account_id", "available_credits", "auto_recharge_threshold_usd", "auto_recharge_amount_usd", "auto_recharge_enabled", "auto_recharge_last_triggered_at", "platform_key", "pricing_table", "free_trial", "current_plan", "previous_plan", "can_use_auto_recharge", "has_payment_method", "message"]

    @field_validator('available_credits')
    def available_credits_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^-?\d{0,14}(?:\.\d{0,4})?$", value):
            raise ValueError(r"must validate the regular expression /^-?\d{0,14}(?:\.\d{0,4})?$/")
        return value

    @field_validator('auto_recharge_threshold_usd')
    def auto_recharge_threshold_usd_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^-?\d{0,11}(?:\.\d{0,3})?$", value):
            raise ValueError(r"must validate the regular expression /^-?\d{0,11}(?:\.\d{0,3})?$/")
        return value

    @field_validator('auto_recharge_amount_usd')
    def auto_recharge_amount_usd_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^-?\d{0,11}(?:\.\d{0,3})?$", value):
            raise ValueError(r"must validate the regular expression /^-?\d{0,11}(?:\.\d{0,3})?$/")
        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 CreditAccountInfo 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "has_credits",
            "account_id",
            "available_credits",
            "auto_recharge_threshold_usd",
            "auto_recharge_amount_usd",
            "auto_recharge_enabled",
            "auto_recharge_last_triggered_at",
            "platform_key",
            "pricing_table",
            "free_trial",
            "current_plan",
            "previous_plan",
            "can_use_auto_recharge",
            "has_payment_method",
            "message",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if auto_recharge_last_triggered_at (nullable) is None
        # and model_fields_set contains the field
        if self.auto_recharge_last_triggered_at is None and "auto_recharge_last_triggered_at" in self.model_fields_set:
            _dict['auto_recharge_last_triggered_at'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "has_credits": obj.get("has_credits"),
            "account_id": obj.get("account_id"),
            "available_credits": obj.get("available_credits"),
            "auto_recharge_threshold_usd": obj.get("auto_recharge_threshold_usd"),
            "auto_recharge_amount_usd": obj.get("auto_recharge_amount_usd"),
            "auto_recharge_enabled": obj.get("auto_recharge_enabled"),
            "auto_recharge_last_triggered_at": obj.get("auto_recharge_last_triggered_at"),
            "platform_key": obj.get("platform_key"),
            "pricing_table": obj.get("pricing_table"),
            "free_trial": obj.get("free_trial"),
            "current_plan": obj.get("current_plan"),
            "previous_plan": obj.get("previous_plan"),
            "can_use_auto_recharge": obj.get("can_use_auto_recharge"),
            "has_payment_method": obj.get("has_payment_method"),
            "message": obj.get("message")
        })
        return _obj


