<?php

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

return new class extends Migration
{
    public function up(): void
    {
        $settings = [
            ['key' => 'sms_provider', 'value' => 'africastalking'],
            ['key' => 'sms_api_key', 'value' => ''],
            ['key' => 'sms_shortcode', 'value' => ''],
            ['key' => 'sms_sender_id', 'value' => ''],
            ['key' => 'sms_enabled', 'value' => '0'],
        ];

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

    public function down(): void
    {
        DB::table('settings')->whereIn('key', [
            'sms_provider',
            'sms_api_key',
            'sms_shortcode',
            'sms_sender_id',
            'sms_enabled',
        ])->delete();
    }
};
