<?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('harvests', function (Blueprint $table) {
            $table->id();
            $table->foreignId('vineyard_row_id')->constrained('vineyard_rows')->onDelete('cascade')->comment('Reference to vineyard row');
            $table->foreignId('variety_variation_id')->constrained('variety_variations')->onDelete('cascade')->comment('Reference to variety variation');
            $table->foreignId('user_id')->nullable()->constrained('users')->onDelete('set null')->comment('User who performed the harvest');
            $table->decimal('weight', 8, 2)->comment('Weight of harvested grapes in kg');
            $table->decimal('sugar_content', 5, 2)->nullable()->comment('Sugar content in NM (°NM)');
            $table->date('date')->comment('Harvest date');
            $table->enum('quality', ['excellent', 'good', 'fair', 'poor'])->nullable()->comment('Quality grade of the harvest');
            $table->string('grape_condition')->nullable()->comment('Condition of grapes at harvest');
            $table->text('notes')->nullable()->comment('Harvest notes and observations');
            $table->text('weather_conditions')->nullable()->comment('Weather conditions during harvest');
            $table->time('harvest_time')->nullable()->comment('Time of day when harvest occurred');
            $table->timestamps();
        });
    }

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