<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $settings = [
            // Verificare Name Servers
            [
                'key' => 'cron_nameserver_check_interval',
                'value' => '5',
                'description' => 'Interval verificare nameservere (minute)',
                'type' => 'integer',
            ],
            [
                'key' => 'cron_nameserver_check_enabled',
                'value' => '1',
                'description' => 'Activează verificare nameservere',
                'type' => 'boolean',
            ],
            
            // Statistici DNS (Ieri)
            [
                'key' => 'cron_statistics_yesterday_interval',
                'value' => '30',
                'description' => 'Interval colectare statistici ieri (minute)',
                'type' => 'integer',
            ],
            [
                'key' => 'cron_statistics_yesterday_limit',
                'value' => '20',
                'description' => 'Limită zone procesate pentru statistici ieri',
                'type' => 'integer',
            ],
            [
                'key' => 'cron_statistics_yesterday_enabled',
                'value' => '1',
                'description' => 'Activează colectare statistici ieri',
                'type' => 'boolean',
            ],
            
            // Statistici DNS (Azi)
            [
                'key' => 'cron_statistics_today_interval',
                'value' => '15',
                'description' => 'Interval colectare statistici azi (minute)',
                'type' => 'integer',
            ],
            [
                'key' => 'cron_statistics_today_limit',
                'value' => '10',
                'description' => 'Limită zone procesate pentru statistici azi',
                'type' => 'integer',
            ],
            [
                'key' => 'cron_statistics_today_enabled',
                'value' => '1',
                'description' => 'Activează colectare statistici azi',
                'type' => 'boolean',
            ],
        ];

        foreach ($settings as $setting) {
            DB::table('settings')->updateOrInsert(
                ['key' => $setting['key']],
                $setting
            );
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        $keys = [
            'cron_nameserver_check_interval',
            'cron_nameserver_check_enabled',
            'cron_statistics_yesterday_interval',
            'cron_statistics_yesterday_limit',
            'cron_statistics_yesterday_enabled',
            'cron_statistics_today_interval',
            'cron_statistics_today_limit',
            'cron_statistics_today_enabled',
        ];

        DB::table('settings')->whereIn('key', $keys)->delete();
    }
};
