<?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::table('documents', function (Blueprint $table) {
            // 添加 Markdown 文件路径字段
            $table->string('markdown_path', 500)->nullable()->after('description');
            
            // 添加 Markdown 内容摘要字段（用于快速预览）
            $table->text('markdown_preview')->nullable()->after('markdown_path');
            
            // 添加转换状态字段
            $table->enum('conversion_status', ['pending', 'processing', 'completed', 'failed'])
                ->default('pending')
                ->after('markdown_preview');
            
            // 添加转换错误信息字段
            $table->text('conversion_error')->nullable()->after('conversion_status');
            
            // 添加索引以优化查询性能
            $table->index('conversion_status');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('documents', function (Blueprint $table) {
            // 删除索引
            $table->dropIndex(['conversion_status']);
            
            // 删除字段
            $table->dropColumn([
                'markdown_path',
                'markdown_preview',
                'conversion_status',
                'conversion_error'
            ]);
        });
    }
};
