<?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_rewards', function (Blueprint $table) {
            $table->id();
            $table->foreignId('referrer_user_id')->constrained('users')->cascadeOnDelete();
            $table->foreignId('referred_user_id')->constrained('users')->cascadeOnDelete();
            $table->foreignId('order_id')->constrained()->cascadeOnDelete();
            $table->char('currency_code', 3)->default('EGP');
            $table->bigInteger('referrer_reward_minor');
            $table->bigInteger('referred_reward_minor')->default(0);
            $table->string('status')->default('paid')->index();
            $table->json('snapshot')->nullable();
            $table->timestamps();
            $table->unique(['referred_user_id', 'order_id']);
        });
    }

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