# coding: utf-8

"""
    Ringer Business API - Account Management

    This API provides endpoints for managing customer accounts in the Ringer Business system. It allows for retrieving account details, updating account information, managing account status (activation/closure), and updating associated addresses.  Account operations typically require authentication and appropriate permissions (e.g., administrator role for certain updates). 

    The version of the OpenAPI document: 1.0.0
    Contact: support@ringer.tel
    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, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from ringer_business.models.address_response import AddressResponse
from ringer_business.models.link import Link
from ringer_business.models.user_summary import UserSummary
from typing import Optional, Set
from typing_extensions import Self

class AccountResponse(BaseModel):
    """
    Detailed information about a customer account.
    """ # noqa: E501
    id: StrictInt = Field(description="Unique identifier for the account.")
    name: StrictStr = Field(description="The official name of the account/company.")
    status: StrictStr = Field(description="Current status of the account.")
    plan: Optional[StrictStr] = Field(default=None, description="Identifier or name of the current subscription plan.")
    email: StrictStr = Field(description="Primary contact email for the account (often billing or admin).")
    phone: Optional[StrictStr] = Field(default=None, description="Primary contact phone number for the account.")
    created_at: datetime = Field(description="Timestamp of when the account was created.")
    locale: StrictStr = Field(description="Preferred language and regional settings for the account.")
    balance: StrictStr = Field(description="Current monetary balance of the account.")
    balance_preference_in_dollars: Optional[StrictStr] = Field(default=None, description="Desired minimum balance to maintain, in dollars.")
    recharge_preference_in_dollars: Optional[StrictStr] = Field(default=None, description="Amount to automatically recharge when balance falls below preference, in dollars.")
    maximum_recharge_preference_in_dollars: Optional[StrictStr] = Field(default=None, description="Maximum permissible auto-recharge amount in a single transaction, in dollars.")
    international_enabled: Optional[StrictBool] = Field(default=None, description="Flag indicating if international calling/services are enabled.")
    current_user: Optional[UserSummary] = None
    address: Optional[AddressResponse] = None
    links: Optional[List[Link]] = Field(default=None, description="HATEOAS links related to the account.")
    __properties: ClassVar[List[str]] = ["id", "name", "status", "plan", "email", "phone", "created_at", "locale", "balance", "balance_preference_in_dollars", "recharge_preference_in_dollars", "maximum_recharge_preference_in_dollars", "international_enabled", "current_user", "address", "links"]

    @field_validator('status')
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['active', 'inactive', 'suspended', 'pending_confirmation', 'closed']):
            raise ValueError("must be one of enum values ('active', 'inactive', 'suspended', 'pending_confirmation', 'closed')")
        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 AccountResponse 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 current_user
        if self.current_user:
            _dict['current_user'] = self.current_user.to_dict()
        # override the default output from pydantic by calling `to_dict()` of address
        if self.address:
            _dict['address'] = self.address.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in links (list)
        _items = []
        if self.links:
            for _item_links in self.links:
                if _item_links:
                    _items.append(_item_links.to_dict())
            _dict['links'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of AccountResponse 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"),
            "name": obj.get("name"),
            "status": obj.get("status"),
            "plan": obj.get("plan"),
            "email": obj.get("email"),
            "phone": obj.get("phone"),
            "created_at": obj.get("created_at"),
            "locale": obj.get("locale"),
            "balance": obj.get("balance"),
            "balance_preference_in_dollars": obj.get("balance_preference_in_dollars"),
            "recharge_preference_in_dollars": obj.get("recharge_preference_in_dollars"),
            "maximum_recharge_preference_in_dollars": obj.get("maximum_recharge_preference_in_dollars"),
            "international_enabled": obj.get("international_enabled"),
            "current_user": UserSummary.from_dict(obj["current_user"]) if obj.get("current_user") is not None else None,
            "address": AddressResponse.from_dict(obj["address"]) if obj.get("address") is not None else None,
            "links": [Link.from_dict(_item) for _item in obj["links"]] if obj.get("links") is not None else None
        })
        return _obj


