<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('file_deletion_logs', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->unsignedBigInteger('file_id')->comment('파일 ID');

            // 파일 정보 (삭제 시점 스냅샷)
            $table->string('file_name', 255)->comment('파일명 (display_name)');
            $table->string('file_path', 1000)->comment('파일 경로');
            $table->bigInteger('file_size')->comment('파일 크기 (bytes)');

            // 연관 정보
            $table->unsignedBigInteger('folder_id')->nullable()->comment('폴더 ID');
            $table->unsignedBigInteger('document_id')->nullable()->comment('문서 ID');
            $table->string('document_type', 100)->nullable()->comment('문서 타입');

            // 삭제 정보
            $table->unsignedBigInteger('deleted_by')->comment('삭제자 ID');
            $table->timestamp('deleted_at')->comment('삭제 시간');
            $table->enum('deletion_type', ['soft', 'permanent'])->default('soft')->comment('삭제 유형');

            // 인덱스
            $table->index(['tenant_id'], 'idx_tenant');
            $table->index(['file_id'], 'idx_file');
            $table->index(['deleted_at'], 'idx_deleted_at');
            $table->index(['deletion_type'], 'idx_deletion_type');

            // 외래키
            $table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('file_deletion_logs');
    }
};
