<?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('wine_productions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('wine_id')->constrained('wines')->onDelete('cascade')->comment('Reference to wine product');
            $table->foreignId('harvest_id')->constrained('harvests')->onDelete('cascade')->comment('Reference to harvest used');
            $table->decimal('consumed_weight', 8, 2)->comment('Weight of grapes consumed from this harvest');
            $table->decimal('blend_percentage', 5, 2)->nullable()->comment('Percentage in blend composition');
            $table->timestamps();

            // Ensure unique combination of wine and harvest
            $table->unique(['wine_id', 'harvest_id']);
        });
    }

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