import unittest

from rcl_rlm.modelrelay import BatchResponse, ModelRelayError


class TestBatchTypedResponse(unittest.TestCase):
    def test_batch_response_missing_id_raises(self) -> None:
        with self.assertRaises(ModelRelayError):
            BatchResponse.from_dict({"results": [], "usage": {}})

    def test_batch_response_missing_results_raises(self) -> None:
        with self.assertRaises(ModelRelayError):
            BatchResponse.from_dict({"id": "batch_1", "usage": {}})

    def test_batch_response_missing_usage_raises(self) -> None:
        with self.assertRaises(ModelRelayError):
            BatchResponse.from_dict({"id": "batch_1", "results": []})

    def test_batch_response_invalid_result_raises(self) -> None:
        payload = {
            "id": "batch_1",
            "results": [{"id": "item-1", "status": "success"}],
            "usage": {},
        }
        with self.assertRaises(ModelRelayError):
            BatchResponse.from_dict(payload)


if __name__ == "__main__":
    unittest.main()
