<?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');

try {
    $adminId = \App\Models\Database::connect()
        ->query("SELECT id FROM users WHERE role = 'super_admin' AND status = 'active' LIMIT 1")
        ->fetch()['id'] ?? 1;

    $service = new \App\Services\BackupService();
    $backup = $service->createBackup((int) $adminId);

    echo date('Y-m-d H:i:s') . " - Backup automático creado: {$backup['file_name']}\n";
} catch (\Exception $e) {
    echo date('Y-m-d H:i:s') . " - Error: {$e->getMessage()}\n";
    exit(1);
}
