"""Helpers to convert tracked usage into billable quantities."""

from __future__ import annotations

from typing import Iterable


class UsageCalculator:
    """Summarize usage records into billable totals."""

    def total(self, records: Iterable[dict], *, metric: str | None = None) -> float:
        value = 0.0
        for record in records:
            if metric and record.get("metric") != metric:
                continue
            value += float(record.get("value", 0.0) or 0.0)
        return value
