"""Tests for StepResponse."""

from restate_saga.step_response import StepResponse


def test_success_response():
    resp = StepResponse(output={"id": 1}, compensation_data={"id": 1})
    assert resp.output == {"id": 1}
    assert resp.compensation_data == {"id": 1}
    assert resp.failed is False
    assert resp.error_message is None


def test_permanent_failure():
    resp = StepResponse.permanent_failure("Something went wrong", {"partial": True})
    assert resp.output is None
    assert resp.compensation_data == {"partial": True}
    assert resp.failed is True
    assert resp.error_message == "Something went wrong"


def test_success_with_none_compensation():
    resp = StepResponse(output="ok", compensation_data=None)
    assert resp.output == "ok"
    assert resp.compensation_data is None
    assert resp.failed is False


def test_compensation_data_defaults_to_output():
    resp = StepResponse(output={"order_id": "123"})
    assert resp.compensation_data == {"order_id": "123"}
    assert resp.compensation_data is resp.output


def test_explicit_compensation_data_not_overridden():
    resp = StepResponse(output={"id": 1}, compensation_data={"id": 1, "extra": True})
    assert resp.compensation_data == {"id": 1, "extra": True}
