<?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('upload_tags', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->uuid('upload_id');
            $table->foreignId('tag_id')->constrained()->cascadeOnDelete();
            $table->decimal('confidence', 5, 4)->nullable();
            $table->string('source', 24)->default('manual')->index(); // ai|filename|manual
            $table->timestamps();

            $table->foreign('upload_id')->references('id')->on('uploads')->cascadeOnDelete();
            $table->unique(['upload_id', 'tag_id']);
        });
    }

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