<?php
header('Content-Type: application/json');

include "../db.php";

error_reporting(E_ERROR | E_PARSE);
ini_set('display_errors', 0);

$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
if (!in_array($method, ['GET', 'DELETE'], true)) {
    echo json_encode(["status" => "error", "message" => "Invalid request method"]);
    exit;
}

$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($id <= 0) {
    echo json_encode(["status" => "error", "message" => "Missing job ID"]);
    exit;
}

$stmt = $conn->prepare("DELETE FROM job_listing WHERE id=?");
$stmt->bind_param("i", $id);

if ($stmt->execute()) {
    echo json_encode(["status" => "success", "message" => "Job deleted successfully"]);
} else {
    echo json_encode(["status" => "error", "message" => "Failed to delete job: " . $stmt->error]);
}

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