<?php

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

return new class extends Migration
{
    public function up(): void
    {
        $settings = [
            'mail_mailer' => config('mail.default', 'log'),
            'mail_host' => config('mail.mailers.smtp.host'),
            'mail_port' => config('mail.mailers.smtp.port'),
            'mail_username' => config('mail.mailers.smtp.username'),
            'mail_password' => config('mail.mailers.smtp.password'),
            'mail_scheme' => config('mail.mailers.smtp.scheme'),
            'mail_from_address' => config('mail.from.address'),
            'mail_from_name' => config('mail.from.name'),
            'sms_driver' => config('services.sms.driver', 'log'),
            'sms_gateway_url' => config('services.sms.url'),
            'sms_gateway_method' => config('services.sms.method', 'POST'),
            'sms_gateway_token' => config('services.sms.token'),
            'sms_from' => config('services.sms.sender', config('app.name')),
            'sms_to_param' => config('services.sms.to_param', 'to'),
            'sms_message_param' => config('services.sms.message_param', 'message'),
            'sms_sender_param' => config('services.sms.sender_param', 'from'),
            'payment_gateway_provider' => config('services.subscription_gateway.provider', 'none'),
            'paystack_secret_key' => config('services.paystack.secret_key'),
            'paystack_base_url' => config('services.paystack.base_url', 'https://api.paystack.co'),
        ];

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

    public function down(): void
    {
        DB::table('system_settings')->whereIn('key', [
            'mail_mailer',
            'mail_host',
            'mail_port',
            'mail_username',
            'mail_password',
            'mail_scheme',
            'mail_from_address',
            'mail_from_name',
            'sms_driver',
            'sms_gateway_url',
            'sms_gateway_method',
            'sms_gateway_token',
            'sms_from',
            'sms_to_param',
            'sms_message_param',
            'sms_sender_param',
            'payment_gateway_provider',
            'paystack_secret_key',
            'paystack_base_url',
        ])->delete();
    }
};
