<?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('documents', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->text('description')->nullable();
            $table->string('file_path', 500);
            $table->string('file_name');
            $table->bigInteger('file_size');
            $table->string('mime_type', 100);
            $table->foreignId('knowledge_base_id')->constrained('knowledge_bases')->cascadeOnDelete();
            $table->foreignId('uploaded_by')->constrained('users')->cascadeOnDelete();
            $table->string('markdown_path', 500)->nullable();
            $table->enum('conversion_status', ['pending', 'processing', 'completed', 'failed'])->default('pending');
            $table->text('conversion_error')->nullable();
            $table->timestamps();

            $table->index('knowledge_base_id');
            $table->index('uploaded_by');
            $table->index('conversion_status');
        });
    }

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