"""Smoke tests to verify package scaffold and dependencies."""

import sys


def test_import_secbulkdownload() -> None:
    """Test that the root package can be imported."""
    import secbulkdownload

    assert secbulkdownload is not None


def test_root_exports_accessible() -> None:
    """Test that all 6 root exports are accessible."""
    from secbulkdownload import (
        filingArchive,
        filingDocument,
        get_ticker_name_dicts,
        headerfile,
        idx,
        rate_limiter,
    )

    # Verify they are defined (not None)
    assert idx is not None
    assert headerfile is not None
    assert filingArchive is not None
    assert filingDocument is not None
    assert rate_limiter is not None
    assert get_ticker_name_dicts is not None


def test_duckdb_importable() -> None:
    """Test that duckdb is importable."""
    import duckdb

    assert duckdb is not None


def test_pandas_not_required() -> None:
    """Test that pandas is NOT in the dependency set.

    This verifies the clean migration to DuckDB.
    """
    # pandas should not be in sys.modules after our imports
    # First, ensure we've imported our package
    import secbulkdownload  # noqa: F401

    # pandas should not have been imported by our package
    # If it was, it would be in sys.modules
    assert "pandas" not in sys.modules, (
        "pandas should not be imported by secbulkdownload - use DuckDB instead"
    )


def test_polars_not_required() -> None:
    """Test that polars is NOT in the dependency set.

    This verifies the simplified plain Python data flow.
    """
    # polars should not be in sys.modules after our imports
    # First, ensure we've imported our package
    import secbulkdownload  # noqa: F401

    # polars should not have been imported by our package
    # If it was, it would be in sys.modules
    assert "polars" not in sys.modules, (
        "polars should not be imported by secbulkdownload - use plain Python data structures"
    )


def test_rate_limiter_instantiable() -> None:
    """Test that rate_limiter can be instantiated."""
    from secbulkdownload import rate_limiter

    limiter = rate_limiter(interval=1.0, limit=10)
    assert limiter is not None
    assert limiter.interval == 1.0
    assert limiter.limit == 10


def test_idx_instantiable() -> None:
    """Test that idx class can be instantiated."""
    from secbulkdownload import idx

    # idx requires user_agent
    instance = idx(user_agent="Test Company test@test.com")
    assert instance is not None
    assert instance.user_agent == "Test Company test@test.com"


def test_headerfile_instantiable() -> None:
    """Test that headerfile class can be instantiated."""
    from secbulkdownload import headerfile

    instance = headerfile(
        sec_filename="edgar/data/0000320193/0000320193-23-000077.txt",
        user_agent="Test Company test@test.com",
    )
    assert instance is not None


def test_filingArchive_instantiable() -> None:
    """Test that filingArchive class can be instantiated."""
    from unittest.mock import patch

    from secbulkdownload import filingArchive

    with patch("secbulkdownload.secfiling.headerfile") as mock_headerfile:
        mock_headerfile.return_value.get_headerDict.return_value = {}

        instance = filingArchive(
            sec_filepath="edgar/data/0000320193/0000320193-23-000077.txt",
            user_agent="Test Company test@test.com",
        )
        assert instance is not None


def test_filingDocument_instantiable() -> None:
    """Test that filingDocument class can be instantiated."""
    from secbulkdownload import filingDocument

    doc = filingDocument(
        filename="test.txt",
        file_type="10-K",
        sequence="1",
        description="Annual report",
        body="Test content",
        html="<html>Test content</html>",
    )
    assert doc is not None
    assert doc.filename == "test.txt"
    assert doc.type == "10-K"


def test_get_ticker_name_dicts_callable() -> None:
    """Test that get_ticker_name_dicts is callable."""
    from secbulkdownload import get_ticker_name_dicts

    # Returns tuple of two dicts (may be empty if no network and no cache)
    ticker_dict, name_dict = get_ticker_name_dicts()
    assert isinstance(ticker_dict, dict)
    assert isinstance(name_dict, dict)
