<?php
session_start();
require 'config.php';
require 'geofencing_service.php';

header('Content-Type: application/json; charset=UTF-8');

if (!isset($_SESSION['user_id'])) {
    http_response_code(401);
    echo json_encode(['status' => 'error', 'message' => 'غير مسموح']);
    exit;
}

$data = json_decode(file_get_contents('php://input'), true);
$geofenceId = $data['id'] ?? null;

if (!$geofenceId) {
    http_response_code(400);
    echo json_encode(['status' => 'error', 'message' => 'معرف المنطقة مطلوب']);
    exit;
}

$geofencingService = new GeofencingService($conn, $_SESSION['user_id']);
$result = $geofencingService->deleteGeofence($geofenceId);

echo json_encode([
    'status' => $result ? 'success' : 'error',
    'message' => $result ? 'تم الحذف بنجاح' : 'فشل الحذف'
], JSON_UNESCAPED_UNICODE);

