<?php
// =====================================================
// POST /add_issue.php
// Params: title
// Response: { status, id }
// =====================================================
require_once 'config.php';

$conn = getConnection();

$title = $_POST['title'] ?? '';

if (empty($title)) {
    echo json_encode(["status" => "error", "message" => "Title is required"]);
    exit;
}

$stmt = $conn->prepare("INSERT INTO issue (title) VALUES (?)");
$stmt->bind_param("s", $title);

if ($stmt->execute()) {
    echo json_encode([
        "status" => "success",
        "id"     => (int)$conn->insert_id
    ]);
} else {
    echo json_encode(["status" => "error", "message" => "Failed to add issue"]);
}

$stmt->close();
$conn->close();
