<?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('sop_templates', function (Blueprint $table) {
            $table->id();
            $table->string('name')->comment('模板名称');
            $table->text('description')->nullable()->comment('模板描述');
            $table->string('category', 100)->nullable()->comment('分类');
            $table->json('tags')->nullable()->comment('标签');
            $table->string('version', 50)->default('1.0.0')->comment('版本号');
            $table->enum('status', ['draft', 'published', 'archived'])->default('draft')->comment('状态');
            $table->json('applicable_departments')->nullable()->comment('适用部门');
            $table->json('applicable_positions')->nullable()->comment('适用岗位');
            $table->timestamp('published_at')->nullable()->comment('发布时间');
            $table->unsignedBigInteger('created_by')->nullable()->comment('创建人');
            $table->timestamps();
            $table->softDeletes();

            // 添加索引
            $table->index('status', 'idx_sop_templates_status');
            $table->index('category', 'idx_sop_templates_category');
        });
    }

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