<?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('bonus_claim_logs', function (Blueprint $table) {
            $table->id();
            $table->string('bonus_type', 30)->index();
            $table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
            $table->unsignedBigInteger('review_id')->nullable()->index();
            $table->string('email')->nullable()->index();
            $table->string('phone', 30)->nullable()->index();
            $table->string('device_identifier')->nullable()->index();
            $table->decimal('bonus_amount', 24, 8)->default(0);
            $table->unsignedInteger('bonus_points')->default(0);
            $table->boolean('granted_status')->default(0)->index();
            $table->string('block_reason')->nullable()->index();
            $table->json('context')->nullable();
            $table->timestamp('attempted_at')->nullable()->index();
            $table->timestamp('granted_at')->nullable();
            $table->timestamps();
        });
    }

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