"""Public SDK surface for contract-attestation."""

from __future__ import annotations

from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as _pkg_version

from .client import AsyncClient, SyncClient
from .errors import (
    APIError,
    AuthenticationError,
    BadRequestError,
    ConnectionError,
    CryptoNotAvailableError,
    PaymentRequiredError,
    RateLimitError,
    ServiceUnavailableError,
    TimeoutError,
    ValidatorError,
)
from .gate import GateCheck, GatePolicy, GateResult, check_contract, evaluate
from .models import (
    AttestationStatus,
    EvidenceLevel,
    Finding,
    HealthResult,
    OnChainStatus,
    ReputationResult,
    ReviewResult,
    Severity,
    StatsResult,
    StatusResult,
)

try:
    __version__ = _pkg_version("contract-attestation")
except PackageNotFoundError:
    __version__ = "0.1.0"

try:
    from ._verify import canonical_serialize, decrypt_findings, verify_response_hash
except Exception as exc:  # pragma: no cover - exercised via fallback wrappers
    _CRYPTO_IMPORT_ERROR = exc

    def _raise_crypto_error() -> None:
        raise CryptoNotAvailableError(
            "Crypto helpers require optional dependencies. Install with [crypto]."
        ) from _CRYPTO_IMPORT_ERROR

    def canonical_serialize(data: dict) -> bytes:  # type: ignore[override]
        _raise_crypto_error()

    def verify_response_hash(ipfs_payload: dict, on_chain_hash: str) -> bool:  # type: ignore[override]
        _raise_crypto_error()

    def decrypt_findings(encrypted_payload: dict, private_key_hex: str) -> dict:  # type: ignore[override]
        _raise_crypto_error()


__all__ = [
    "APIError",
    "AsyncClient",
    "AttestationStatus",
    "AuthenticationError",
    "BadRequestError",
    "ConnectionError",
    "CryptoNotAvailableError",
    "EvidenceLevel",
    "Finding",
    "GateCheck",
    "GatePolicy",
    "GateResult",
    "HealthResult",
    "OnChainStatus",
    "PaymentRequiredError",
    "RateLimitError",
    "ReputationResult",
    "ReviewResult",
    "ServiceUnavailableError",
    "Severity",
    "StatsResult",
    "StatusResult",
    "SyncClient",
    "TimeoutError",
    "ValidatorError",
    "__version__",
    "canonical_serialize",
    "check_contract",
    "decrypt_findings",
    "evaluate",
    "verify_response_hash",
]
