"""Tests for the public API surface exported from repo_core.__init__."""

from __future__ import annotations

import pytest


def test_all_exports_are_importable():
    """Verify every name in __all__ can be imported from repo_core."""
    from repo_core import __all__ as public_names

    for name in public_names:
        # Import the name dynamically to avoid unused-import warnings
        mod = __import__("repo_core", fromlist=[name])
        obj = getattr(mod, name, None)
        assert obj is not None, f"'{name}' is in __all__ but cannot be imported"


def test_base_repository_exported():
    from repo_core import BaseRepository
    assert BaseRepository is not None


def test_domain_model_exported():
    from repo_core import DomainModel
    assert DomainModel is not None


def test_schemas_exported():
    from repo_core import BaseRequestSchema, BaseResponseSchema, BasePatchSchema
    assert BaseRequestSchema is not None
    assert BaseResponseSchema is not None
    assert BasePatchSchema is not None


def test_validators_exported():
    from repo_core import (
        ValidationError,
        BaseValidator,
        ValidatorPipeline,
        RequiredValidator,
        MaxLengthValidator,
    )
    assert ValidationError is not None
    assert BaseValidator is not None
    assert ValidatorPipeline is not None
    assert RequiredValidator is not None
    assert MaxLengthValidator is not None


def test_db_core_reexports():
    from repo_core import PostgresClient, create_postgres_client, QueryBuilder, QuerySet
    assert PostgresClient is not None
    assert create_postgres_client is not None
    assert QueryBuilder is not None
    assert QuerySet is not None


def test_events_exported():
    from repo_core import HookRegistry, hook
    assert HookRegistry is not None
    assert hook is not None


def test_migrations_exported():
    from repo_core import MigrationBuilder, Migration, MigrationRunner
    assert MigrationBuilder is not None
    assert Migration is not None
    assert MigrationRunner is not None


def test_domain_subpackages_importable():
    """Domain sub-packages should be importable."""
    from repo_core.domains.article import Article, CreateArticleRequest, ArticleResponse
    from repo_core.domains.entity import Entity, CreateEntityRequest, EntityResponse
    assert Article is not None
    assert Entity is not None


def test_domain_article_all_names_exported():
    from repo_core.domains.article import __all__ as article_names
    expected = {"Article", "CreateArticleRequest", "PatchArticleRequest", "ArticleResponse", "ArticleTitleValidator"}
    assert set(article_names) == expected


def test_domain_entity_all_names_exported():
    from repo_core.domains.entity import __all__ as entity_names
    expected = {"Entity", "CreateEntityRequest", "PatchEntityRequest", "EntityResponse", "EntityNameValidator"}
    assert set(entity_names) == expected
