<?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('mortality_headers', function (Blueprint $table) {
            $table->increments("id");
            $table->unsignedInteger("farm_id")->index();
            $table->foreign("farm_id")
                ->references("id")
                ->on("farms");
            $table->string("farm_code")->index();
            $table->string("farm_name");
            $table->date("week_start_date")->index()->nullable();
            $table->date("week_end_date")->index()->nullable();
            $table->integer("week_number")->index();
            $table->integer("year")->index()->nullable();
            $table->integer("total_mortality")->default(0);
            $table
                ->string("synced_status")
                ->default("unsynced")
                ->index();
            $table->timestamp("synced_at")->nullable();
            $table->integer("synced_id")->nullable();
            $table->integer("created_by")->index();
            $table->softDeletes();
            $table->timestamps();
        });
    }

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