from __future__ import annotations

from datetime import datetime
from typing import Protocol

from .models import Link


class StripePort(Protocol):
    def has_default_payment_method(self, customer_id: str) -> bool: ...
    def ensure_metered_subscription(self, customer_id: str) -> str: ...
    def cancel_subscription_if_any(self, customer_id: str) -> None: ...
    def report_usage(
        self, subscription_item_id: str, units: int, timestamp: int, idempotency_key: str
    ) -> None: ...


class UsageSourcePort(Protocol):
    def get_usage(
        self, usage_plan_id: str, api_key_id: str, since: datetime, until: datetime
    ) -> int | None: ...


class PlanAdminPort(Protocol):
    def move_key_to_plan(self, api_key_id: str, target_plan_id: str) -> None: ...


class CustomerRepoPort(Protocol):
    def get_by_api_key(self, api_key_id: str) -> Link: ...
    def get_by_customer(self, customer_id: str) -> list[Link]: ...
    def save(self, link: Link) -> None: ...
    def scan_metered(self) -> list[Link]: ...
