<?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('harvest_records', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('farm_id')->default(1);
            $table->foreignId('pond_id')->constrained()->cascadeOnDelete();
            $table->foreignId('cycle_id')->constrained('production_cycles')->cascadeOnDelete();
            $table->date('harvest_date');
            $table->unsignedInteger('total_fish_harvested');
            $table->decimal('total_weight_kg', 10, 2);
            $table->unsignedInteger('total_mortality_count')->default(0);
            $table->enum('harvest_type', ['full_harvest', 'partial_harvest']);
            $table->text('harvest_notes')->nullable();
            $table->foreignId('logged_by')->constrained('users');
            $table->timestamps();
            $table->softDeletes();

            $table->index(['pond_id', 'cycle_id']);
        });
    }

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