from magento.sync_planner import (
    ACTION_UPSERT_MEDIA,
    ACTION_UPSERT_PRODUCT,
    ACTION_SET_RELATIONS,
    plan_incremental_sync,
)


def test_images_only_plans_media_not_product():
    row = {
        "sku": "SKU-1",
        "name": "Test",
        "base_image": "https://cdn.example/a.jpg",
        "additional_images": "https://cdn.example/b.jpg",
    }
    plan = plan_incremental_sync(
        1,
        [row],
        {},
        catalog_state_by_sku={"SKU-1": {"magento_product_id": 99}},
        images_only=True,
    )
    actions = [a.action for a in plan.actions]
    assert ACTION_UPSERT_MEDIA in actions
    assert ACTION_UPSERT_PRODUCT not in actions
    assert ACTION_SET_RELATIONS not in actions


def test_images_only_skips_media_when_product_missing():
    row = {
        "sku": "SKU-2",
        "base_image": "https://cdn.example/a.jpg",
    }
    plan = plan_incremental_sync(
        1,
        [row],
        {},
        catalog_state_by_sku={},
        images_only=True,
    )
    actions = [a.action for a in plan.actions]
    assert ACTION_UPSERT_MEDIA in actions
    assert ACTION_UPSERT_PRODUCT not in actions


def test_products_only_plans_product_not_media():
    row = {
        "sku": "SKU-3",
        "name": "Test",
        "base_image": "https://cdn.example/a.jpg",
        "additional_images": "https://cdn.example/b.jpg",
    }
    plan = plan_incremental_sync(
        1,
        [row],
        {},
        products_only=True,
    )
    actions = [a.action for a in plan.actions]
    assert ACTION_UPSERT_PRODUCT in actions
    assert ACTION_UPSERT_MEDIA not in actions
