<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('settings', function (Blueprint $table) {
            $table->id();
            $table->string('key')->unique();
            $table->longText('value')->nullable();
            $table->boolean('encrypted')->default(false);
            $table->timestamps();
        });

        Schema::create('payments', function (Blueprint $table) {
            $table->id();
            $table->string('gateway');                       // mpesa | paystack | flutterwave
            $table->string('reference')->unique();           // our reference
            $table->string('gateway_reference')->nullable(); // provider's id/receipt
            $table->string('status')->default('pending');    // pending | paid | failed | cancelled
            $table->unsignedBigInteger('amount');            // minor units (cents)
            $table->string('currency', 3)->default('KES');
            $table->string('purpose')->nullable();           // consultation | course:slug | ...
            $table->nullableMorphs('payable');               // e.g. Consultation, Enrollment
            $table->string('email')->nullable();
            $table->string('phone')->nullable();
            $table->json('meta')->nullable();
            $table->timestamp('paid_at')->nullable();
            $table->timestamps();
        });
    }

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