<?php

declare(strict_types=1);

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_tag', function (Blueprint $table): void {
            $table->unsignedBigInteger('artwork_id');
            $table->unsignedBigInteger('tag_id');
            $table->enum('source', ['user', 'ai', 'system']);
            $table->float('confidence')->nullable();
            $table->timestamp('created_at')->useCurrent();

            $table->primary(['artwork_id', 'tag_id']);
            $table->index('tag_id');

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

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