# coding: utf-8

"""
    Qoetry API

    Qoetry API for dataset collection and management. Start dataset collection jobs, monitor their progress, and download results as CSV files.  ## Authentication  **All endpoints require API key authentication** (except `/health` and `/`).  You can provide your API key via: - Query parameter: `?api_key=your_api_key` - Header: `x-api-key: your_api_key` - Header: `Authorization: Bearer your_api_key`  ## Rate Limits  API calls are subject to monthly quotas based on your subscription plan. Quota information is available via the `/v0/usage` endpoint. 

    The version of the OpenAPI document: 0.5.0
    Contact: samuel.tinnerholm@gmail.com
    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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List
from typing_extensions import Annotated
from qoery.models.get_usage_stats200_response_endpoint_breakdown_inner import GetUsageStats200ResponseEndpointBreakdownInner
from typing import Optional, Set
from typing_extensions import Self

class GetUsageStats200Response(BaseModel):
    """
    Complete usage statistics for a user
    """ # noqa: E501
    user_id: StrictStr = Field(description="User identifier")
    plan: StrictStr = Field(description="Current subscription plan. Possible values: - `free`: Free tier with basic limits - `starter`: Starter plan for small projects - `pro`: Professional plan for production use - `growth`: Growth plan for large-scale operations ")
    total_usage: Annotated[int, Field(strict=True, ge=0)] = Field(description="Total number of API calls across all endpoints", alias="totalUsage")
    total_errors: Annotated[int, Field(strict=True, ge=0)] = Field(description="Total number of errors across all endpoints", alias="totalErrors")
    endpoint_breakdown: List[GetUsageStats200ResponseEndpointBreakdownInner] = Field(description="Usage breakdown by endpoint", alias="endpointBreakdown")
    __properties: ClassVar[List[str]] = ["user_id", "plan", "totalUsage", "totalErrors", "endpointBreakdown"]

    @field_validator('plan')
    def plan_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['free', 'starter', 'pro', 'growth']):
            raise ValueError("must be one of enum values ('free', 'starter', 'pro', 'growth')")
        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 GetUsageStats200Response 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 endpoint_breakdown (list)
        _items = []
        if self.endpoint_breakdown:
            for _item_endpoint_breakdown in self.endpoint_breakdown:
                if _item_endpoint_breakdown:
                    _items.append(_item_endpoint_breakdown.to_dict())
            _dict['endpointBreakdown'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "user_id": obj.get("user_id"),
            "plan": obj.get("plan"),
            "totalUsage": obj.get("totalUsage"),
            "totalErrors": obj.get("totalErrors"),
            "endpointBreakdown": [GetUsageStats200ResponseEndpointBreakdownInner.from_dict(_item) for _item in obj["endpointBreakdown"]] if obj.get("endpointBreakdown") is not None else None
        })
        return _obj


