"""Public configuration types for the Partner Ecosystem SDK."""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Any, Dict, Optional

DEFAULT_JWKS_PATH = "/.well-known/jwks.json"


@dataclass
class DeductionRequest:
    """Body of a :meth:`PartnerEcosystemClient.send_deduction_request` call."""

    #: Amount to deduct from the credit wallet.
    amount: float
    #: Arbitrary metadata to attach to the deduction.
    meta: Optional[Dict[str, Any]] = field(default=None)
    #: External reference id (e.g. for idempotency / reconciliation).
    reference: str = ""
    #: Free-text note describing the deduction.
    note: str = ""


@dataclass
class JwksOptions:
    """Tuning for the remote JWKS fetch + cache."""

    #: How long (seconds) a fetched key set is considered fresh.
    cache_max_age: Optional[float] = None
    #: Maximum number of signing keys to keep cached.
    max_cached_keys: Optional[int] = None
    #: Timeout (seconds) for the JWKS HTTP request.
    timeout_duration: Optional[float] = None


@dataclass
class PartnerEcosystemConfig:
    """Configuration passed to :func:`ab_ecosystem.init` at start-up."""

    #: Base URL of the Partner Ecosystem API, e.g. ``https://api.example.com``.
    api_url: str
    #: Public identifier of the project.
    project_id: str
    #: Secret used to authenticate server-to-server calls.
    project_secret: str
    #: Path (relative to ``api_url``) of the JWKS endpoint.
    jwks_path: str = DEFAULT_JWKS_PATH
    #: Expected ``iss`` claim of incoming tokens. ``None`` disables the check.
    issuer: Optional[str] = None
    #: Expected ``aud`` claim of incoming tokens. Defaults to ``project_id``.
    audience: Optional[str] = None
    #: Tuning for the remote JWKS fetch + cache.
    jwks: Optional[JwksOptions] = None
