<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('receta_ingredientes', function (Blueprint $table) {
            $table->id();
            $table->foreignId('receta_id')->constrained()->cascadeOnDelete();
            $table->foreignId('insumo_id')->constrained()->restrictOnDelete();
            $table->enum('tipo', ['principal', 'accesorio'])->default('principal');
            $table->decimal('cantidad', 10, 4);
            $table->timestamps();

            // Un insumo no puede repetirse en la misma receta
            $table->unique(['receta_id', 'insumo_id']);
        });
    }

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