<?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::connection('mysql')->create('mpesa_transactions', function (Blueprint $table) {
            $table->id();
            $table->string('merchant_request_id')->nullable()->index();
            $table->string('checkout_request_id')->nullable()->index();
            $table->string('originator_conversation_id')->nullable()->index(); // For B2C
            $table->enum('transaction_type', ['TOPUP', 'BILL_PAYMENT', 'SALARY']);
            $table->string('phone_number');
            $table->decimal('amount', 10, 2);
            $table->string('mpesa_receipt_number')->nullable();
            $table->enum('status', ['PENDING', 'SUCCESS', 'FAILED'])->default('PENDING');
            $table->json('raw_callback_payload')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void {
        Schema::connection('mysql')->dropIfExists('mpesa_transactions');
    }
};

