<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create("batches", function (Blueprint $table) {
            $table->increments("id");

            $table->integer("farm_id")->index();
            $table->string("farm_name")->index();
            $table->integer("building_id")->index();
            $table->string("building_name")->index();
            $table->string("batch_no")->index();
            $table->integer("batch_sequence")->index();
            // $table->integer("batch_year")->index();
            $table->date("start_date")->index();
            $table->date("end_date")->nullable();
            $table
                ->string("status")
                ->default("active")
                ->index();
            $table
                ->string("synced_status")
                ->default("unsynced")
                ->index();
            $table->timestamp("synced_at")->nullable();
            $table->integer("synced_id")->nullable();
            $table->integer("initial_population")->default(0);
            $table->integer("original_population")->default(0);
            $table->integer("current_population")->default(0);
            $table->integer("total_culled")->default(0);
            $table->integer("total_mortality")->default(0);
            $table->integer("total_harvested")->default(0);
            $table->string("attachment_path")->nullable();
            $table->string("attachment_uploaded_at")->nullable();
            $table->timestamps();
            $table->softDeletes();
            $table->index(["farm_id", "start_date"]);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists("batches");
    }
};
