<?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('credit_purchases', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->unsignedTinyInteger('credits_requested');   // 1, 5, or 10
            $table->unsignedInteger('amount_tzs');              // amount driver should send
            $table->string('payment_method', 20);               // mpesa | tigopesa | airtel | yasmix
            $table->string('payment_phone', 20);                // driver's mobile money number
            $table->string('reference', 60)->nullable();        // USSD transaction ref
            $table->enum('status', ['pending', 'completed', 'rejected'])->default('pending');
            $table->text('admin_note')->nullable();
            $table->timestamp('completed_at')->nullable();
            $table->timestamps();
        });
    }

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