<?php

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

return new class extends Migration
{
    public function up(): void
    {
        $settings = [
            'whatsapp_driver' => config('services.whatsapp.driver', 'log'),
            'whatsapp_gateway_url' => config('services.whatsapp.url'),
            'whatsapp_gateway_method' => config('services.whatsapp.method', 'POST'),
            'whatsapp_gateway_token' => config('services.whatsapp.token'),
            'whatsapp_from' => config('services.whatsapp.sender', config('app.name')),
            'whatsapp_to_param' => config('services.whatsapp.to_param', 'to'),
            'whatsapp_message_param' => config('services.whatsapp.message_param', 'message'),
            'whatsapp_sender_param' => config('services.whatsapp.sender_param', 'from'),
        ];

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

    public function down(): void
    {
        DB::table('system_settings')->whereIn('key', [
            'whatsapp_driver',
            'whatsapp_gateway_url',
            'whatsapp_gateway_method',
            'whatsapp_gateway_token',
            'whatsapp_from',
            'whatsapp_to_param',
            'whatsapp_message_param',
            'whatsapp_sender_param',
        ])->delete();
    }
};
