<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('topspender_rewards', function (Blueprint $table) {
            $table->id();
            $table->unsignedTinyInteger('month'); // 1-12
            $table->unsignedSmallInteger('year');
            $table->unsignedTinyInteger('rank'); // 1, 2, or 3
            $table->unsignedInteger('item_id');
            $table->string('item_name');
            $table->unsignedInteger('item_count')->default(1);
            $table->text('mail_message')->nullable();
            $table->unsignedInteger('created_by')->nullable();
            $table->timestamps();

            // Unique constraint: one reward per rank per month/year
            $table->unique(['month', 'year', 'rank']);
            $table->index(['month', 'year']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('topspender_rewards');
    }
};
