<?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('stock_transfer_ins', function (Blueprint $table) {
            $table->id();
            $table->string('document_no')->unique();
            $table->unsignedBigInteger('stock_transfer_out_id');
            $table->unsignedInteger('destination_farm_id');
            $table->date('received_date');
            $table->text('remarks')->nullable();
            $table->unsignedBigInteger('user_id');
            $table->timestamps();
            $table->softDeletes();

            $table->foreign('stock_transfer_out_id')->references('id')->on('stock_transfer_outs');
            $table->foreign('destination_farm_id')->references('id')->on('farms');
            $table->foreign('user_id')->references('id')->on('users');

            // Indexes
            $table->index('destination_farm_id', 'sti_destination_farm_idx');
            $table->index('stock_transfer_out_id', 'sti_transfer_out_idx');
            $table->index('received_date', 'sti_received_date_idx');
            $table->index(['destination_farm_id', 'stock_transfer_out_id'], 'sti_farm_transfer_out_idx');
        });
    }

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