<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * Creates the self_paced_paystack_configs table — stores the Paystack
     * gateway credentials (encrypted) and supported currencies for the
     * self-paced learning portal's Paystack Inline JS integration.
     */
    public function up(): void
    {
        Schema::create('self_paced_paystack_configs', function (Blueprint $table) {
            $table->id();

            // Encrypted Paystack credentials (stored via Laravel's encrypt())
            $table->text('public_key');   // pk_live_... or pk_test_...
            $table->text('secret_key');   // sk_live_... or sk_test_...
            $table->text('webhook_secret'); // Paystack webhook signature secret

            // Active currency codes, e.g. ["KES", "NGN"]
            $table->json('currencies')->default('["KES"]');

            // Status
            $table->boolean('is_active')->default(true);

            // Audit
            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();

            $table->foreign('created_by')->references('id')->on('users')->nullOnDelete();
            $table->foreign('updated_by')->references('id')->on('users')->nullOnDelete();

            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('self_paced_paystack_configs');
    }
};
