from __future__ import annotations

from dataclasses import dataclass


@dataclass
class ExternalApiPolicy:
    disabled: bool = False
    compliance_approved: bool = False
    metadata_logging_accepted: bool = False
    allow_online_sync: bool = False
    daily_limit: int | None = None
    calls_made: int = 0

    def can_call(self) -> tuple[bool, str | None]:
        if self.disabled:
            return False, "external API disabled"
        if not self.compliance_approved:
            return False, "external API compliance not approved"
        if not self.metadata_logging_accepted:
            return False, "metadata logging not accepted"
        if not self.allow_online_sync:
            return False, "online synchronous mode not allowed"
        if self.daily_limit is not None and self.calls_made >= self.daily_limit:
            return False, "external API usage limit reached"
        return True, None

    def record_call(self) -> None:
        self.calls_made += 1
