from __future__ import annotations

from dataclasses import dataclass
from typing import Optional, Protocol


@dataclass
class FBR:
    id: str
    org_id: str
    idempotency_key: str
    status: str = "pending"
    price_book_version: str = "p0-0"
    billing_mode: str = "resell"
    prompt_tokens: int = 0
    completion_tokens: int = 0
    cost_usd: float = 0.0
    api_key_id: Optional[str] = None


class BillingStore(Protocol):
    def seed(
        self,
        fbr_id: str,
        org_id: str,
        idem_key: str,
        price_book_version: str,
        *,
        billing_mode: str,
        api_key_id: Optional[str],
    ) -> FBR: ...

    def record_delta(self, fbr_id: str, prompt: int, completion: int, cost_usd: float) -> None: ...

    def finalize(self, fbr_id: str) -> Optional[FBR]: ...
