# coding: utf-8

"""
    bxb API

    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.5.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, StrictStr
from typing import Any, ClassVar, Dict, List
from bxb.models.collection_metrics import CollectionMetrics
from bxb.models.daily_revenue_point import DailyRevenuePoint
from bxb.models.net_revenue_metrics import NetRevenueMetrics
from bxb.models.revenue_by_type_breakdown import RevenueByTypeBreakdown
from bxb.models.top_customer_revenue import TopCustomerRevenue
from typing import Optional, Set
from typing_extensions import Self

class RevenueAnalyticsResponse(BaseModel):
    """
    RevenueAnalyticsResponse
    """ # noqa: E501
    daily_revenue: List[DailyRevenuePoint]
    revenue_by_type: List[RevenueByTypeBreakdown]
    top_customers: List[TopCustomerRevenue]
    collection: CollectionMetrics
    net_revenue: NetRevenueMetrics
    currency: StrictStr
    __properties: ClassVar[List[str]] = ["daily_revenue", "revenue_by_type", "top_customers", "collection", "net_revenue", "currency"]

    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 RevenueAnalyticsResponse 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 each item in daily_revenue (list)
        _items = []
        if self.daily_revenue:
            for _item_daily_revenue in self.daily_revenue:
                if _item_daily_revenue:
                    _items.append(_item_daily_revenue.to_dict())
            _dict['daily_revenue'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in revenue_by_type (list)
        _items = []
        if self.revenue_by_type:
            for _item_revenue_by_type in self.revenue_by_type:
                if _item_revenue_by_type:
                    _items.append(_item_revenue_by_type.to_dict())
            _dict['revenue_by_type'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in top_customers (list)
        _items = []
        if self.top_customers:
            for _item_top_customers in self.top_customers:
                if _item_top_customers:
                    _items.append(_item_top_customers.to_dict())
            _dict['top_customers'] = _items
        # override the default output from pydantic by calling `to_dict()` of collection
        if self.collection:
            _dict['collection'] = self.collection.to_dict()
        # override the default output from pydantic by calling `to_dict()` of net_revenue
        if self.net_revenue:
            _dict['net_revenue'] = self.net_revenue.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "daily_revenue": [DailyRevenuePoint.from_dict(_item) for _item in obj["daily_revenue"]] if obj.get("daily_revenue") is not None else None,
            "revenue_by_type": [RevenueByTypeBreakdown.from_dict(_item) for _item in obj["revenue_by_type"]] if obj.get("revenue_by_type") is not None else None,
            "top_customers": [TopCustomerRevenue.from_dict(_item) for _item in obj["top_customers"]] if obj.get("top_customers") is not None else None,
            "collection": CollectionMetrics.from_dict(obj["collection"]) if obj.get("collection") is not None else None,
            "net_revenue": NetRevenueMetrics.from_dict(obj["net_revenue"]) if obj.get("net_revenue") is not None else None,
            "currency": obj.get("currency")
        })
        return _obj


