<?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_metadata', function (Blueprint $table) {
            $table->id();
            $table->string('file_path'); // Path to the file on the filesystem
            $table->string('file_name'); // Original file name
            $table->unsignedBigInteger('folder_id')->nullable(); // Associated folder
            $table->string('meta_tag'); // Tag name (e.g., 'Department', 'Project')
            $table->text('meta_value'); // Tag value (e.g., 'HR', 'ProjectX')
            $table->unsignedBigInteger('uploaded_by')->nullable(); // User who uploaded
            $table->timestamps();
            
            // Foreign keys
            $table->foreign('folder_id')->references('id')->on('folders')->onDelete('cascade');
            $table->foreign('uploaded_by')->references('id')->on('users')->onDelete('set null');
            
            // Indexes
            $table->index(['file_path', 'meta_tag']);
            $table->index('folder_id');
        });
    }

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