"""Structural tests for the systems blueprint — registration + handler/service
contracts. Full HTTP integration needs a live DB + auth the unit env lacks."""
import inspect


def test_systems_blueprint_registered():
    from scribe.routes.systems import systems_bp
    assert systems_bp.name == "systems"
    assert systems_bp.url_prefix == "/api/projects"


def test_systems_blueprint_registered_in_app():
    from scribe.app import create_app
    app = create_app()
    assert "systems" in app.blueprints


def test_system_handlers_callable():
    from scribe.routes import systems as routes
    for name in (
        "list_systems_route", "create_system_route", "get_system_route",
        "update_system_route", "delete_system_route", "system_records_route",
        "project_issues_route",
    ):
        assert callable(getattr(routes, name))


def test_service_functions_take_user_id():
    """Routes must call systems services with user_id — verify the contract."""
    from scribe.services import systems as svc
    for fn_name in (
        "create_system", "list_systems", "get_system", "update_system",
        "delete_system", "list_records_for_system", "list_issues",
        "open_issue_counts_by_system",
    ):
        fn = getattr(svc, fn_name)
        assert callable(fn)
        assert "user_id" in inspect.signature(fn).parameters
