<?php

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

/**
 * PRC-1143 — konsolide şema: `product_config_option_dependencies` tablosunun TAM tanımı (tek dosya).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('product_config_option_dependencies', function (Blueprint $t) {
            $t->id();
            $t->unsignedBigInteger('group_id');
            $t->unsignedBigInteger('source_option_id');
            $t->enum('operator', ['equals','not_equals','in','any'])->default('equals');
            $t->unsignedBigInteger('source_value_id')->nullable();
            $t->json('source_value_ids')->nullable();
            $t->unsignedBigInteger('target_option_id');
            $t->enum('action', ['show','hide','require','optional'])->default('show');
            $t->unsignedInteger('order')->default(0);
            $t->timestamp('created_at')->nullable();
            $t->timestamp('updated_at')->nullable();
            $t->index(['group_id', 'source_option_id'], 'pcod_group_source_idx');
            $t->index('target_option_id', 'pcod_target_idx');
            $t->index('source_option_id', 'product_config_option_dependencies_source_option_id_foreign');
            $t->foreign('group_id', 'product_config_option_dependencies_group_id_foreign')->references('id')->on('product_config_option_groups')->onDelete('cascade');
            $t->foreign('source_option_id', 'product_config_option_dependencies_source_option_id_foreign')->references('id')->on('product_config_options')->onDelete('cascade');
            $t->foreign('target_option_id', 'product_config_option_dependencies_target_option_id_foreign')->references('id')->on('product_config_options')->onDelete('cascade');
        });
    }

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