<?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('productos_variantes_definiciones', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('producto_variante_id');
            $table->foreignId('attribute_id')->constrained('productos_attributes')->cascadeOnUpdate()->cascadeOnDelete();
            $table->text('value')->nullable();
            $table->timestamps();

            $table->foreign('producto_variante_id')
                ->references('id')
                ->on('productos_variantes')
                ->cascadeOnUpdate()
                ->cascadeOnDelete();

            $table->unique(['producto_variante_id', 'attribute_id'], 'prod_var_def_variant_attr_unique');
        });
    }

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