<?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('treatment_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('pond_id')->constrained()->cascadeOnDelete();
            $table->foreignId('cycle_id')->constrained('production_cycles')->cascadeOnDelete();
            $table->date('treatment_date');
            $table->string('drug_chemical_name');
            $table->string('dosage');
            $table->enum('application_method', ['bath', 'oral_feed', 'injection', 'pond_broadcast']);
            $table->unsignedInteger('duration_days')->nullable();
            $table->unsignedInteger('withdrawal_period_days')->nullable();
            $table->date('harvest_safe_after')->nullable();
            $table->decimal('cost_naira', 15, 2)->nullable();
            $table->string('administered_by')->nullable();
            $table->enum('outcome', ['resolved', 'ongoing', 'worsened', 'inconclusive'])->nullable();
            $table->text('notes')->nullable();
            $table->foreignId('logged_by')->constrained('users');
            $table->timestamps();

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

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