"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .quotatier import QuotaTier
from datetime import datetime
from factify.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class OrganizationQuotaTypedDict(TypedDict):
    r"""OrganizationQuota represents the quota status for an organization."""

    current_usage: NotRequired[int]
    r"""Current usage in the billing period."""
    effective_limit: NotRequired[int]
    r"""The effective monthly limit (explicit limit if set, otherwise tier default)."""
    is_exceeded: NotRequired[bool]
    r"""Whether quota is exceeded."""
    organization_id: NotRequired[str]
    r"""The organization ID.
    Pattern: org_[0-9a-hjkmnp-tv-z]{26}
    """
    period_start: NotRequired[datetime]
    r"""Start of current billing period."""
    remaining: NotRequired[int]
    r"""Remaining requests in the billing period."""
    reset_at: NotRequired[datetime]
    r"""When the quota resets (start of next billing period)."""
    tier: NotRequired[QuotaTier]
    usage_percent: NotRequired[int]
    r"""Usage as a percentage (0-100+)."""


class OrganizationQuota(BaseModel):
    r"""OrganizationQuota represents the quota status for an organization."""

    current_usage: Optional[int] = None
    r"""Current usage in the billing period."""

    effective_limit: Optional[int] = None
    r"""The effective monthly limit (explicit limit if set, otherwise tier default)."""

    is_exceeded: Optional[bool] = None
    r"""Whether quota is exceeded."""

    organization_id: Optional[str] = None
    r"""The organization ID.
    Pattern: org_[0-9a-hjkmnp-tv-z]{26}
    """

    period_start: Optional[datetime] = None
    r"""Start of current billing period."""

    remaining: Optional[int] = None
    r"""Remaining requests in the billing period."""

    reset_at: Optional[datetime] = None
    r"""When the quota resets (start of next billing period)."""

    tier: Optional[QuotaTier] = None

    usage_percent: Optional[int] = None
    r"""Usage as a percentage (0-100+)."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "current_usage",
                "effective_limit",
                "is_exceeded",
                "organization_id",
                "period_start",
                "remaining",
                "reset_at",
                "tier",
                "usage_percent",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
