<?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('consignments', function (Blueprint $table) {
        $table->id();
        $table->foreignId('shipment_id')
              ->constrained()
              ->cascadeOnDelete();
        $table->string('house_waybill_no')->nullable();
        $table->string('container_no')->nullable();
        $table->string('customer_name');
        $table->string('phone');
        $table->string('destination')->default('NBI');
        $table->text('description')->nullable();
        $table->decimal('pcs', 8, 2)->default(0);
        $table->decimal('actual_weight_kgs', 8, 3)->nullable();
        $table->decimal('cbm', 8, 3)->nullable();
        $table->decimal('extra_charge_usd', 10, 2)->default(0);
        $table->decimal('amount_usd', 10, 2)->default(0);
        $table->decimal('amount_kes', 10, 2)->default(0);
        $table->enum('status', [
            'in_transit',
            'in_warehouse',
            'ready_for_pickup',
            'delivered',
        ])->default('in_transit');
        $table->string('collected_by')->nullable();
        $table->timestamp('collected_at')->nullable();
        $table->foreignId('created_by')
              ->nullable()
              ->constrained('users')
              ->nullOnDelete();
        $table->timestamps();
    });
}

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