<?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_interactive_tasks', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('sop_step_id')->comment('步骤ID');
            $table->enum('task_type', ['confirm', 'input', 'select', 'photo', 'scan'])->comment('任务类型');
            $table->json('task_config')->nullable()->comment('任务配置');
            $table->json('validation_rules')->nullable()->comment('验证规则');
            $table->integer('timeout_seconds')->nullable()->comment('超时时间');
            $table->boolean('is_required')->default(true)->comment('是否必需');
            $table->timestamps();

            // 添加外键约束
            $table->foreign('sop_step_id')
                  ->references('id')
                  ->on('sop_steps')
                  ->onDelete('cascade');
        });
    }

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