<?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('referral_activity_log', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('referral_id')->nullable();
            $table->unsignedInteger('member_id')->nullable();
            $table->string('action', 50);
            $table->text('details')->nullable();
            $table->string('ip_address', 45)->nullable();
            $table->timestamp('created_at')->useCurrent();

            $table->foreign('referral_id')->references('id')->on('referrals')->onDelete('set null');
            $table->index('referral_id');
            $table->index('member_id');
            $table->index('action');
        });
    }

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