<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

session_start();

require_once __DIR__ . '/../core/functions.php';
require_once __DIR__ . '/../services/UserAlertService.php';

if (!isset($_SESSION['user_id'])) {
    header("Location: ../public/login.php");
    exit;
}

$userId = (int)$_SESSION['user_id'];
$alertId = isset($_POST['alert_id']) ? (int)$_POST['alert_id'] : 0;

if ($alertId <= 0) {
    die("Invalid alert.");
}

UserAlertService::deleteAlert($alertId, $userId);

header("Location: my_alerts.php?deleted=1");
exit;