<?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('artwork_awards', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('artwork_id');
            $table->unsignedBigInteger('user_id');
            $table->enum('medal', ['gold', 'silver', 'bronze']);
            $table->tinyInteger('weight')->unsigned()->default(1);
            $table->timestamps();

            $table->unique(['artwork_id', 'user_id']);
            $table->index('artwork_id');
            $table->index('user_id');

            $table->foreign('artwork_id')
                ->references('id')->on('artworks')
                ->cascadeOnDelete();

            $table->foreign('user_id')
                ->references('id')->on('users')
                ->cascadeOnDelete();
        });
    }

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