"""download_backends — the single predicate that routes a platform to the
native ingester vs. gallery-dl. Pure, no DB."""

from backend.app.services.download_backends import (
    NATIVE_INGESTER_PLATFORMS,
    _campaign_resolution_error,
    _native_ingester_cls,
    uses_native_ingester,
)
from backend.app.services.pixiv_ingester import PixivIngester


def test_native_platforms():
    for platform in ("patreon", "subscribestar", "pixiv"):
        assert uses_native_ingester(platform) is True
        assert platform in NATIVE_INGESTER_PLATFORMS


def test_gallery_dl_platforms_are_not_native():
    # The platforms still served by gallery-dl must NOT route to the native
    # ingester — guards an accidental over-broad migration.
    for platform in ("hentaifoundry", "discord"):
        assert uses_native_ingester(platform) is False


def test_unknown_platform_is_not_native():
    assert uses_native_ingester("nonsense") is False


def test_pixiv_dispatches_to_its_ingester():
    assert _native_ingester_cls("pixiv") is PixivIngester


def test_pixiv_resolution_error_names_the_expected_url_shape():
    msg = _campaign_resolution_error("pixiv", "https://www.pixiv.net/artworks/1")
    assert "pixiv user id" in msg
    assert "users/<id>" in msg
