<?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('easy_out_dispatches', function (Blueprint $table) {
            $table->id();
            $table->string('reference_number', 30)->unique();
            $table->date('dispatch_date');
            $table->string('item_description');
            $table->string('unit', 50);
            $table->decimal('quantity', 10, 2);
            $table->foreignId('project_id')->constrained('projects')->onDelete('restrict');
            $table->foreignId('division_id')->nullable()->constrained('project_divisions')->onDelete('set null');
            $table->string('purpose', 255)->nullable();
            $table->string('received_by', 150)->nullable();
            $table->text('notes')->nullable();
            $table->foreignId('created_by')->constrained('users')->onDelete('restrict');
            $table->timestamps();
            $table->softDeletes();

            $table->index('dispatch_date');
            $table->index('project_id');
            $table->index('reference_number');
        });
    }

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