<?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('cars', function (Blueprint $table) {
            $table->id();
            $table->integer('price')->nullable();
            $table->integer('number_of_places');
            $table->string('immatriculation')->nullable();
            $table->text('description')->nullable();
            $table->integer('status')->default(1);
            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();
            $table->unsignedBigInteger('brand_id')->nullable();
            $table->unsignedBigInteger('modele_id')->nullable();
            $table->unsignedBigInteger('cartype_id')->nullable();
            $table->unsignedBigInteger('fueltype_id')->nullable();
            $table->unsignedBigInteger('transmissiontype_id')->nullable();
            $table->unsignedBigInteger('color_id')->nullable();
            $table->boolean('active')->default(100);
            $table->softDeletes();
            $table->integer('deleted_by')->nullable();

            // Foreign key
            $table->foreign('created_by')->references('id')->on('users');
            $table->foreign('updated_by')->references('id')->on('users');
            $table->foreign('brand_id')->references('id')->on('brands');
            $table->foreign('modele_id')->references('id')->on('modeles');
            $table->foreign('cartype_id')->references('id')->on('car_types');
            $table->foreign('fueltype_id')->references('id')->on('fuel_types');
            $table->foreign('transmissiontype_id')->references('id')->on('transmission_types');
            $table->foreign('color_id')->references('id')->on('colors');
            $table->timestamps();
        });
    }

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