<?php

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

/**
 * Multi-source migration desteği — Phase 2.
 *
 * source_panel: 'cpanel' | 'directadmin' | 'plesk'
 *
 * Bu kolon migration_jobs row açılırken set edilir; parser + sysapi action
 * dispatch'i bu kolona göre yapılır:
 *
 *   cpanel       → cpanel-test-connection, cpanel-list-remote-accounts,
 *                  cpanel-pull-remote, CpanelPkgactParser
 *   directadmin  → directadmin-test-connection, directadmin-list-accounts,
 *                  directadmin-pull-remote, DirectAdminBackupParser
 *   plesk        → plesk-test-connection, plesk-list-subscriptions,
 *                  plesk-pull-remote, PleskBackupParser
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('migration_jobs', function (Blueprint $table) {
            $table->enum('source_panel', ['cpanel', 'directadmin', 'plesk'])
                ->default('cpanel')
                ->after('initiated_by')
                ->comment('Hangi panelden geliyor — sysapi + parser dispatch için');
        });

        // Mevcut satırlar zaten cPanel
        DB::table('migration_jobs')->update(['source_panel' => 'cpanel']);
    }

    public function down(): void
    {
        Schema::table('migration_jobs', function (Blueprint $table) {
            $table->dropColumn('source_panel');
        });
    }
};
