<?php

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

/**
 * PRC-318 / D-13 — domain sync redesign migration.
 *
 *  - (PRC-619) Şablon seed kısmı CommunicationTemplateSeeder'a taşındı.
 *  - Drop the legacy `domain_*_sync_frequency` enum settings (D-11 swaps to
 *    cycle-period semantic via `domain_*_sync_cycle_days`).
 */
return new class extends Migration
{
    public function up(): void
    {
        // D-11 — drop legacy enum settings (replaced by domain_*_sync_cycle_days).
        DB::table('settings')->whereIn('key', [
            'domain_sync_frequency',
            'domain_expiring_sync_frequency',
            'domain_transfer_sync_frequency',
        ])->delete();
    }

    public function down(): void
    {
        // Re-seed legacy enum keys with sensible defaults so the old
        // Kernel.php logic could run if reverted.
        foreach (['domain_sync_frequency' => 'daily', 'domain_expiring_sync_frequency' => 'every_6_hours', 'domain_transfer_sync_frequency' => 'every_6_hours'] as $key => $val) {
            DB::table('settings')->updateOrInsert(
                ['key' => $key],
                ['value' => $val, 'group' => 'domains', 'created_at' => now(), 'updated_at' => now()]
            );
        }
    }
};
