<?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('mortality_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('pond_id')->constrained()->cascadeOnDelete();
            $table->foreignId('cycle_id')->constrained('production_cycles')->cascadeOnDelete();
            $table->date('log_date');
            $table->unsignedInteger('dead_count');
            $table->decimal('estimated_avg_weight_g', 8, 2)->nullable();
            $table->enum('probable_cause', ['disease', 'water_quality', 'predator', 'injury', 'unknown'])->nullable();
            $table->text('symptoms_observed')->nullable();
            $table->text('notes')->nullable();
            $table->foreignId('logged_by')->constrained('users');
            $table->timestamps();

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

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