<?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_version_events', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('artwork_id')->index();
            $table->unsignedBigInteger('user_id')->index();
            $table->string('action', 50); // create_version | restore_version
            $table->unsignedBigInteger('version_id')->nullable();
            $table->timestamps();

            $table->foreign('artwork_id', 'fk_avevt_artwork')
                ->references('id')->on('artworks')->cascadeOnDelete();
            $table->foreign('user_id', 'fk_avevt_user')
                ->references('id')->on('users')->cascadeOnDelete();
        });
    }

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