<?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
    {
        if (Schema::hasTable('welcome_offer_claims')) {
            return;
        }

        Schema::create('welcome_offer_claims', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->unique();
            $table->unsignedBigInteger('admin_id')->nullable()->index();
            $table->string('claim_source', 50)->default('user_claim')->index();
            $table->decimal('reward_amount', 12, 2)->default(0);
            $table->unsignedInteger('level_one_target')->default(0);
            $table->unsignedInteger('level_two_target')->default(0);
            $table->unsignedInteger('level_one_count')->default(0);
            $table->unsignedInteger('level_two_count')->default(0);
            $table->text('note')->nullable();
            $table->timestamp('claimed_at')->nullable()->index();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        if (!Schema::hasTable('welcome_offer_claims')) {
            return;
        }

        Schema::drop('welcome_offer_claims');
    }
};
