#!/usr/bin/env python3
"""Tiny JSON health/API stub for Tech Forge curl labs. Binds 127.0.0.1:9092 only."""
from http.server import BaseHTTPRequestHandler, HTTPServer

HOST, PORT = "127.0.0.1", 9092
BODY = b'{"status":"ok","service":"lab-api","version":"0.1"}'


class H(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(BODY)))
        self.send_header("X-Lab-Helper", "techforge-health-stub")
        self.end_headers()
        self.wfile.write(BODY)

    def log_message(self, *a):
        pass


if __name__ == "__main__":
    if HOST not in ("127.0.0.1", "localhost", "::1"):
        raise SystemExit("Refusing to bind outside loopback.")
    print(f"health stub on http://{HOST}:{PORT}/  (Ctrl+C to stop)")
    HTTPServer((HOST, PORT), H).serve_forever()
