<?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('parking_histories', function (Blueprint $table) {
            $table->id();
            $table->foreignId('parking_id')->constrained('parkings')->cascadeOnDelete();
            $table->timestamp('entry_at');
            $table->timestamp('exit_at')->nullable();
            $table->unsignedInteger('duration_minutes')->nullable();
            $table->timestamps();
        });

        Schema::table('parking_histories', function (Blueprint $table) {
            $table->index(['parking_id', 'entry_at']);
        });
    }

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