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

from __future__ import annotations
from .getusagehistoryresponse import (
    GetUsageHistoryResponse,
    GetUsageHistoryResponseTypedDict,
)
from datetime import datetime
from factify.types import BaseModel, UNSET_SENTINEL
from factify.utils import FieldMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class GetUsageHistoryRequestTypedDict(TypedDict):
    organization_id: NotRequired[str]
    r"""Optional: organization ID to query. If not provided, uses the caller's organization."""
    date_after: NotRequired[datetime]
    r"""Return results after this timestamp (inclusive)."""
    date_before: NotRequired[datetime]
    r"""Return results before this timestamp (inclusive)."""


class GetUsageHistoryRequest(BaseModel):
    organization_id: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Optional: organization ID to query. If not provided, uses the caller's organization."""

    date_after: Annotated[
        Optional[datetime],
        pydantic.Field(alias="date.after"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Return results after this timestamp (inclusive)."""

    date_before: Annotated[
        Optional[datetime],
        pydantic.Field(alias="date.before"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Return results before this timestamp (inclusive)."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["organization_id", "date.after", "date.before"])
        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


class GetUsageHistoryResponseResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: GetUsageHistoryResponseTypedDict


class GetUsageHistoryResponseResponse(BaseModel):
    headers: Dict[str, List[str]]

    result: GetUsageHistoryResponse
