<?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('water_quality_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('pond_id')->constrained()->cascadeOnDelete();
            $table->foreignId('cycle_id')->nullable()->constrained('production_cycles')->nullOnDelete();
            $table->date('reading_date');
            $table->time('reading_time');
            $table->decimal('ph', 4, 2);
            $table->decimal('dissolved_oxygen_mgl', 5, 2);
            $table->decimal('temperature_c', 4, 1);
            $table->decimal('ammonia_ppm', 6, 4)->nullable();
            $table->decimal('nitrite_ppm', 6, 4)->nullable();
            $table->enum('turbidity', ['clear', 'slightly_turbid', 'turbid', 'very_turbid'])->nullable();
            $table->string('water_colour')->nullable();
            $table->text('corrective_action')->nullable();
            $table->foreignId('logged_by')->constrained('users');
            $table->timestamps();

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

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