<?php

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

/**
 * PRC-1143 — konsolide şema: `workflow_nodes` tablosunun TAM tanımı (tek dosya).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('workflow_nodes', function (Blueprint $t) {
            $t->id();
            $t->unsignedBigInteger('workflow_id');
            $t->enum('type', ['trigger','condition','action','chain']);
            $t->json('config')->nullable();
            $t->integer('position_x')->default(0);
            $t->integer('position_y')->default(0);
            $t->timestamp('created_at')->nullable();
            $t->timestamp('updated_at')->nullable();
            $t->index(['workflow_id', 'type'], 'workflow_nodes_workflow_id_type_index');
            $t->foreign('workflow_id', 'workflow_nodes_workflow_id_foreign')->references('id')->on('workflows')->onDelete('cascade');
        });
    }

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