<?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('shipment_vehicle_dispatches', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->comment('테넌트 ID');
            $table->foreignId('shipment_id')->comment('출하 ID');
            $table->integer('seq')->default(1)->comment('순번');
            $table->string('logistics_company', 100)->nullable()->comment('물류사');
            $table->datetime('arrival_datetime')->nullable()->comment('도착일시');
            $table->string('tonnage', 20)->nullable()->comment('톤수');
            $table->string('vehicle_no', 20)->nullable()->comment('차량번호');
            $table->string('driver_contact', 50)->nullable()->comment('운전자 연락처');
            $table->text('remarks')->nullable()->comment('비고');
            $table->timestamps();
            $table->softDeletes();

            // 인덱스
            $table->index(['shipment_id', 'seq']);

            // 외래키
            $table->foreign('shipment_id')->references('id')->on('shipments')->onDelete('cascade');
        });
    }

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