<?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('batch_split_sessions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->foreignId('source_batch_id')->constrained('batches')->cascadeOnDelete();
            $table->date('date');
            $table->unsignedInteger('fish_count_theoretical')->default(0);
            $table->unsignedInteger('fish_count_counted')->default(0);
            $table->unsignedInteger('fish_missing')->default(0);
            $table->unsignedInteger('fish_moved_total')->default(0);
            $table->unsignedInteger('fish_remaining_source')->default(0);
            $table->unsignedInteger('biomass_moved_total_kg')->default(0);
            $table->decimal('avg_weight_reference_g', 10, 2)->default(0);
            $table->text('notes')->nullable();
            $table->timestamps();

            $table->index(['user_id', 'date']);
            $table->index(['source_batch_id', 'date']);
        });
    }

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