<?php
require_once __DIR__ . "/../config/database.php";

$stmt = $pdo->prepare("
    DELETE FROM workers
    WHERE status = 'zaposlen'
      AND updated_at IS NOT NULL
      AND updated_at < (NOW() - INTERVAL 7 DAY)
");
$stmt->execute();
$deleted = $stmt->rowCount();

$log = $pdo->prepare("INSERT INTO audit_log (user_id, action, created_at) VALUES (NULL, ?, NOW())");
$log->execute(["Cron cleanup deleted {$deleted} employed workers older than 7 days"]);

echo "Cleanup completed. Deleted: {$deleted}\n";
