<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('backup_destinations', function (Blueprint $table) {
            $table->id();
            
            // Identificare
            $table->string('name'); // Ex: "FTP Server Principal", "Google Drive Backup"
            $table->enum('type', ['local', 'ftp', 'sftp', 'ssh', 's3', 'google_drive'])->default('local');
            
            // Status
            $table->boolean('is_active')->default(true);
            $table->boolean('is_default')->default(false); // Destinație default pentru backup automat
            
            // Configurare generală
            $table->json('config'); // Configurare specifică fiecărui tip
            /* Exemple config:
             * FTP: {"host": "ftp.example.com", "port": 21, "username": "user", "password": "encrypted", "path": "/backups"}
             * SFTP: {"host": "sftp.example.com", "port": 22, "username": "user", "private_key": "encrypted", "path": "/backups"}
             * S3: {"bucket": "my-backups", "region": "us-east-1", "key": "encrypted", "secret": "encrypted", "path": "backups/"}
             * Google Drive: {"folder_id": "abc123", "credentials": "encrypted"}
             */
            
            // Limite și opțiuni
            $table->integer('max_backups')->default(10); // Număr maxim de backup-uri păstrate
            $table->integer('retention_days')->default(10); // Zile de păstrare
            $table->bigInteger('max_storage_mb')->nullable(); // Limită spațiu (MB)
            
            // Statistici
            $table->integer('total_backups')->default(0);
            $table->bigInteger('total_size_mb')->default(0);
            $table->timestamp('last_backup_at')->nullable();
            $table->timestamp('last_test_at')->nullable();
            $table->enum('last_test_status', ['success', 'failed', 'pending'])->nullable();
            $table->text('last_test_message')->nullable();
            
            $table->timestamps();
            
            // Indexuri
            $table->index('type');
            $table->index('is_active');
            $table->index('is_default');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('backup_destinations');
    }
};
