<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // Insert default settings if they don't exist
        $settings = [
            [
                'key' => 'seller_retention_period',
                'value' => '3',
                'group' => 'data_retention',
                'type' => 'number',
                'label' => 'Seller Account Deletion Grace Period (Months)',
                'created_at' => now(),
                'updated_at' => now()
            ],
            [
                'key' => 'rfq_retention_period',
                'value' => '6',
                'group' => 'data_retention',
                'type' => 'number',
                'label' => 'RFQ Auto-Delete Period (Months)',
                'created_at' => now(),
                'updated_at' => now()
            ]
        ];

        foreach ($settings as $setting) {
            if (!DB::table('settings')->where('key', $setting['key'])->exists()) {
                DB::table('settings')->insert($setting);
            }
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        DB::table('settings')->whereIn('key', ['seller_retention_period', 'rfq_retention_period'])->delete();
    }
};
