from __future__ import annotations

from tests.harness.test_runner import TestCase

SUITE = "test_errors"


def _invalid_json(ctx):
    code, body = ctx.client.raw_post("/api/prompt/agent", b"{not json")
    assert code == 400, f"expected 400, got {code} body={body}"
    return True, "invalid json rejected", {"status": code}


def _missing_message(ctx):
    code, body = ctx.client.raw_post("/api/prompt/agent", b"{}")
    assert code == 400, f"expected 400, got {code} body={body}"
    return True, "missing message rejected", {"status": code}


def _unknown_endpoint(ctx):
    code, _body = ctx.client.raw_post("/api/nonexistent", b"{}")
    assert code == 404, f"expected 404, got {code}"
    return True, "unknown endpoint 404", {"status": code}


def _webhook_nonexistent(ctx):
    code, _body = ctx.client.raw_post("/api/trigger/nonexistent-dtag", b"{}")
    assert code == 404, f"expected 404, got {code}"
    return True, "nonexistent d_tag 404", {"status": code}


def get_tests():
    return [
        TestCase(SUITE, "invalid_json_body", "Malformed JSON rejected", _invalid_json),
        TestCase(SUITE, "missing_message_field", "Missing message field rejected", _missing_message),
        TestCase(SUITE, "unknown_endpoint", "Unknown endpoint returns 404", _unknown_endpoint),
        TestCase(SUITE, "webhook_nonexistent_dtag", "Unknown webhook dtag returns 404", _webhook_nonexistent),
    ]
