from __future__ import annotations

import pytest

from recoil.execution.providers.base import UnifiedVideoPayload
from recoil.execution.providers.kling import KlingAdapter


def test_kling_generation_raises_when_reference_images_would_be_dropped(
    monkeypatch,
):
    monkeypatch.setenv("FAL_KEY", "test-key")
    adapter = KlingAdapter()
    payload = UnifiedVideoPayload(
        prompt="render this",
        reference_images=["https://example.test/ref.png"],
        model_id="kling-o3",
    )

    with pytest.raises(ValueError, match="reference_images require hints"):
        adapter.build_submit(payload, "standard")


def test_kling_generation_allows_reference_images_with_elements(monkeypatch):
    monkeypatch.setenv("FAL_KEY", "test-key")
    adapter = KlingAdapter()
    payload = UnifiedVideoPayload(
        prompt="render this",
        reference_images=["https://example.test/ref.png"],
        hints={"elements": [{"image_url": "https://example.test/ref.png"}]},
        model_id="kling-o3",
    )

    req = adapter.build_submit(payload, "standard")

    assert "reference-to-video" in req.url
    assert req.body["elements"] == [{"image_url": "https://example.test/ref.png"}]
