# 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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from flexprice.models.dto_usage_analytic_point import DtoUsageAnalyticPoint
from flexprice.models.types_aggregation_type import TypesAggregationType
from typing import Optional, Set
from typing_extensions import Self

class DtoUsageAnalyticItem(BaseModel):
    """
    DtoUsageAnalyticItem
    """ # noqa: E501
    aggregation_type: Optional[TypesAggregationType] = None
    currency: Optional[StrictStr] = None
    event_count: Optional[StrictInt] = Field(default=None, description="Number of events that contributed to this aggregation")
    event_name: Optional[StrictStr] = None
    feature_id: Optional[StrictStr] = None
    name: Optional[StrictStr] = None
    points: Optional[List[DtoUsageAnalyticPoint]] = None
    properties: Optional[Dict[str, StrictStr]] = Field(default=None, description="Stores property values for flexible grouping (e.g., org_id -> \"org123\")")
    source: Optional[StrictStr] = None
    total_cost: Optional[Union[StrictFloat, StrictInt]] = None
    total_usage: Optional[Union[StrictFloat, StrictInt]] = None
    unit: Optional[StrictStr] = None
    unit_plural: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["aggregation_type", "currency", "event_count", "event_name", "feature_id", "name", "points", "properties", "source", "total_cost", "total_usage", "unit", "unit_plural"]

    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 DtoUsageAnalyticItem 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 points (list)
        _items = []
        if self.points:
            for _item_points in self.points:
                if _item_points:
                    _items.append(_item_points.to_dict())
            _dict['points'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "aggregation_type": obj.get("aggregation_type"),
            "currency": obj.get("currency"),
            "event_count": obj.get("event_count"),
            "event_name": obj.get("event_name"),
            "feature_id": obj.get("feature_id"),
            "name": obj.get("name"),
            "points": [DtoUsageAnalyticPoint.from_dict(_item) for _item in obj["points"]] if obj.get("points") is not None else None,
            "properties": obj.get("properties"),
            "source": obj.get("source"),
            "total_cost": obj.get("total_cost"),
            "total_usage": obj.get("total_usage"),
            "unit": obj.get("unit"),
            "unit_plural": obj.get("unit_plural")
        })
        return _obj


