<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up()
    {
        Schema::create('workflow_tasks', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('instance_id');
            $table->unsignedBigInteger('document_id');
            $table->unsignedBigInteger('assigned_role')->nullable();
            $table->unsignedBigInteger('assigned_user')->nullable();
            $table->string('status')->default('pending');
            $table->string('current_stage')->nullable();
            $table->timestamps();

            $table->foreign('instance_id')->references('id')->on('workflow_instances')->onDelete('cascade');
            $table->foreign('document_id')->references('id')->on('documents')->onDelete('cascade');
            $table->foreign('assigned_role')->references('id')->on('roles')->onDelete('set null');
            $table->foreign('assigned_user')->references('id')->on('users')->onDelete('set null');
        });
    }
    public function down()
    {
        Schema::dropIfExists('workflow_tasks');
    }
};
