"""Tests for the FastAPI adapter."""

from crystflux.v1.adapters.fastapi import crystflux_request_body, crystflux_response
from crystflux.v1 import LatentValue


# TODO: This test suite is a minimal implementation to begin testing FastAPI integration.
# It is currently insufficient and needs to be expanded to cover various scenarios,
# including different modes (Strict, Dream), error handling, and more complex data structures.


def test_crystflux_request_body_basic():
    payload = {"name": "Test", "value": 123}
    latent_value = crystflux_request_body(payload)
    assert isinstance(latent_value, LatentValue)
    assert latent_value.as_json_value() == payload


def test_crystflux_response_basic():
    data = {"result": "success"}
    latent_value = LatentValue(data)
    response_data = crystflux_response(latent_value)
    assert response_data == LatentValue(data).as_json_value()


def test_crystflux_request_body_nested():
    payload = {"user": {"id": 1, "name": "Alice"}, "items": [10, 20]}
    latent_value = crystflux_request_body(payload)
    assert isinstance(latent_value, LatentValue)
    assert latent_value.get("user").get("name").as_str() == "Alice"
    assert latent_value.get("items").as_int_array() == (10, 20)


def test_crystflux_response_nested():
    data = {"user": {"id": 1, "name": "Alice"}, "items": [10, 20]}
    latent_value = LatentValue(data)
    response_data = crystflux_response(latent_value)
    assert response_data == LatentValue(data).as_json_value()
