<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

require_once "config/config.php";
include("Data.class.php");

$Data = new Data($pdo);

// Alle Termine mit Status 3 und vorhandener calendar_event_id holen
$stmt = $pdo->prepare("
    SELECT id, calendar_event_id
    FROM termine
    WHERE status = 3
      AND calendar_event_id IS NOT NULL
      AND calendar_event_id != ''
");

$stmt->execute();

while ($termin = $stmt->fetch(PDO::FETCH_ASSOC)) {

    // Kalendereintrag löschen
    $Data->deleteCalendarEvent($termin['id']);

    // Optional: calendar_event_id zurücksetzen
    $update = $pdo->prepare("
        UPDATE termine
        SET calendar_event_id = NULL
        WHERE id = ?
    ");

    $update->execute([$termin['id']]);
}

?>