<?php

declare(strict_types=1);

require_once __DIR__ . '/../vendor/autoload.php';

use Dotenv\Dotenv;

$dotenv = Dotenv::createImmutable(dirname(__DIR__));
$dotenv->safeLoad();

define('BASE_PATH', dirname(__DIR__));
define('STORAGE_PATH', BASE_PATH . '/storage');
define('APP_ENV', $_ENV['APP_ENV'] ?? 'development');

date_default_timezone_set('America/Lima');

$db = \App\Models\Database::connect();

$db->exec("DELETE FROM sessions WHERE expires_at < NOW()");
echo date('Y-m-d H:i:s') . " - Sesiones expiradas eliminadas\n";

$db->exec("UPDATE user_invitations SET status = 'expirada' WHERE status = 'pendiente' AND expires_at < NOW()");
echo date('Y-m-d H:i:s') . " - Invitaciones expiradas actualizadas\n";

$db->exec("UPDATE password_resets SET used = 1 WHERE used = 0 AND expires_at < NOW()");
echo date('Y-m-d H:i:s') . " - Tokens de recuperación expirados invalidados\n";
