<?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::table('artworks', function (Blueprint $table) {
            // FK to the active version row (nullable – set after first version is created)
            $table->unsignedBigInteger('current_version_id')->nullable()->index()->after('hash');

            // Running count of how many versions exist
            $table->unsignedInteger('version_count')->default(1)->after('current_version_id');

            // Last time the file was replaced
            $table->timestamp('version_updated_at')->nullable()->after('version_count');

            // Signals that a moderator must approve the new file
            $table->boolean('requires_reapproval')->default(false)->after('version_updated_at');
        });
    }

    public function down(): void
    {
        Schema::table('artworks', function (Blueprint $table) {
            $table->dropIndex(['current_version_id']);
            $table->dropColumn([
                'current_version_id',
                'version_count',
                'version_updated_at',
                'requires_reapproval',
            ]);
        });
    }
};
