<?php

declare(strict_types=1);

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

class CreateShipmentsTable extends Migration
{
    public function up()
    {
        Schema::create('shipments', function (Blueprint $table) {
            $table->id();
            $table->string('tracking_number')->nullable();
            $table->intOrBigIntBasedOnRelated('address_id', Schema::connection(null), 'addresses.id')->unsigned();
            $table->boolean('is_trackable')->default(true);
            $table->string('status')->default('new');
            $table->decimal('weight', 15, 4)->nullable();
            $table->decimal('height', 15, 4)->nullable();
            $table->decimal('width', 15, 4)->nullable();
            $table->decimal('length', 15, 4)->nullable();
            $table->text('comment')->nullable();
            $table->json('configuration')->nullable();
            $table->timestamps();

            $table->foreign('address_id')
                  ->references('id')
                  ->on('addresses');
        });
    }

    public function down()
    {
        Schema::drop('shipments');
    }
}
