<?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('stocking_records', function (Blueprint $table) {
            $table->id();
            $table->foreignId('pond_id')->constrained()->cascadeOnDelete();
            $table->foreignId('cycle_id')->constrained('production_cycles')->cascadeOnDelete();
            $table->date('stocking_date');
            $table->string('species');
            $table->string('strain_variety')->nullable();
            $table->unsignedInteger('quantity');
            $table->decimal('avg_weight_g', 8, 2);
            $table->string('supplier_name');
            $table->string('supplier_contact')->nullable();
            $table->decimal('cost_per_fingerling', 15, 2);
            $table->decimal('transport_cost', 15, 2)->default(0);
            $table->text('notes')->nullable();
            $table->foreignId('logged_by')->constrained('users');
            $table->timestamps();
            $table->softDeletes();

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

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