<?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('definition_values', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('definition_id');
            $table->unsignedBigInteger('definition_attribute_id');
            $table->text('value')->nullable();
            $table->timestamps();

            // Foreign Keys
            $table->foreign('definition_id')->references('id')->on('definitions')->onDelete('cascade');
            $table->foreign('definition_attribute_id')->references('id')->on('definition_attributes')->onDelete('cascade');

            // Indexes
            $table->index(['definition_id', 'definition_attribute_id']);
            $table->index('definition_attribute_id');

            // Unique constraint - her definition için her attribute'un sadece bir değeri olabilir
            $table->unique(['definition_id', 'definition_attribute_id']);
        });
    }

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