<?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
    {
        if (Schema::hasTable('deleted_records')) {
            return;
        }

        Schema::create('deleted_records', function (Blueprint $table) {
            $table->id();
            $table->string('type');
            $table->unsignedBigInteger('record_id');
            $table->string('record_label')->nullable();
            $table->foreignId('deleted_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamp('deleted_at');
            $table->timestamp('restored_at')->nullable();
            $table->foreignId('restored_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamp('force_deleted_at')->nullable();
            $table->foreignId('force_deleted_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();

            $table->index(['type', 'deleted_at']);
            $table->index(['type', 'record_id']);
        });
    }

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