<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $settings = [
            [
                'key' => 'razorpay_key',
                'value' => '',
                'group' => 'payment',
                'type' => 'text',
                'label' => 'Razorpay Key ID',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'key' => 'razorpay_secret',
                'value' => '',
                'group' => 'payment',
                'type' => 'text',
                'label' => 'Razorpay Key Secret',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'key' => 'paypal_client_id',
                'value' => '',
                'group' => 'payment',
                'type' => 'text',
                'label' => 'PayPal Client ID',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'key' => 'paypal_secret',
                'value' => '',
                'group' => 'payment',
                'type' => 'text',
                'label' => 'PayPal Secret',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'key' => 'paypal_mode',
                'value' => 'sandbox',
                'group' => 'payment',
                'type' => 'select', // sandbox or live
                'label' => 'PayPal Mode',
                'created_at' => now(),
                'updated_at' => now(),
            ],
        ];

        DB::table('settings')->upsert($settings, ['key'], ['value', 'group', 'type', 'label', 'updated_at']);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        DB::table('settings')->where('group', 'payment')->delete();
    }
};
