<?php

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

return new class extends Migration
{
    public function up(): void
    {
        $settings = [
            ['key' => 'sms_oauth_client_id', 'value' => ''],
            ['key' => 'sms_oauth_client_secret', 'value' => ''],
            ['key' => 'sms_oauth_access_token', 'value' => ''],
            ['key' => 'sms_oauth_refresh_token', 'value' => ''],
            ['key' => 'sms_oauth_token_expires', 'value' => ''],
        ];

        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_oauth_client_id',
            'sms_oauth_client_secret',
            'sms_oauth_access_token',
            'sms_oauth_refresh_token',
            'sms_oauth_token_expires',
        ])->delete();
    }
};
