<?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_change_logs', function (Blueprint $table) {
            $table->id();
            $table->unsignedTinyInteger('farm_id')->default(1);
            $table->foreignId('pond_id')->constrained()->cascadeOnDelete();
            $table->foreignId('cycle_id')->nullable()->constrained('production_cycles')->nullOnDelete();
            $table->date('change_date');
            $table->enum('change_type', ['partial', 'full'])->default('partial');
            $table->decimal('percentage_changed', 5, 1)->nullable();
            $table->decimal('volume_changed_litres', 10, 2)->nullable();
            $table->string('reason', 255)->nullable();
            $table->text('notes')->nullable();
            $table->foreignId('logged_by')->constrained('users');
            $table->timestamps();

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

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