<?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('carrito_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('cart_id')->constrained('carritos')->cascadeOnUpdate()->cascadeOnDelete();
            $table->unsignedBigInteger('producto_variante_id');
            $table->unsignedInteger('cantidad');
            $table->timestamps();

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

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

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