<?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('vehicles', function (Blueprint $t) {
            $t->id();
            $t->foreignId('company_id')->constrained()->cascadeOnDelete();
            $t->foreignId('client_id')->constrained()->cascadeOnDelete();

            $t->string('make');                  // BMW, Audi, ...
            $t->string('model');                 // X5, A4, ...
            $t->smallInteger('year')->nullable();
            $t->string('vin', 32)->nullable();
            $t->string('plate', 16)->nullable();

            $t->string('engine')->nullable();    // 3.0i / 2.0 TDI
            $t->string('gearbox')->nullable();
            $t->string('fuel')->nullable();
            $t->unsignedInteger('mileage')->default(0);
            $t->string('color')->nullable();
            $t->text('notes')->nullable();

            $t->timestamps();
            $t->softDeletes();

            $t->index(['company_id', 'client_id']);
            $t->index(['company_id', 'plate']);
        });
    }

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