<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     * Ajoute les nouveaux paramètres du site si ils n'existent pas
     */
    public function up(): void
    {
        $newSettings = [
            ['key' => 'slogan', 'value' => 'Portez le luxe, Récoltez le succès'],
            ['key' => 'copyright_text', 'value' => 'Tous droits réservés.'],
            ['key' => 'opening_hours', 'value' => 'Lun - Ven: 8h - 18h | Sam: 9h - 15h'],
            ['key' => 'facebook_url', 'value' => ''],
            ['key' => 'instagram_url', 'value' => ''],
            ['key' => 'twitter_url', 'value' => ''],
            ['key' => 'whatsapp_number', 'value' => ''],
        ];
        
        foreach ($newSettings as $setting) {
            // Insérer seulement si la clé n'existe pas déjà
            $exists = DB::table('site_settings')->where('key', $setting['key'])->exists();
            if (!$exists) {
                DB::table('site_settings')->insert([
                    'key' => $setting['key'],
                    'value' => $setting['value'],
                    'created_at' => now(),
                    'updated_at' => now(),
                ]);
            }
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        $keysToRemove = [
            'slogan', 'copyright_text', 'opening_hours',
            'facebook_url', 'instagram_url', 'twitter_url', 'whatsapp_number'
        ];
        
        DB::table('site_settings')->whereIn('key', $keysToRemove)->delete();
    }
};
