<?php

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

/**
 * PERF-01 / DB-01 from the system analysis: pickup_datetime is the single
 * most-filtered/sorted column in the app (jobs table, reports, mobile
 * history) and had no index at all; status columns on drivers/vehicles/users
 * are filtered constantly (active/inactive lists) but only company_id/role_id
 * get an index today via their FK constraints.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('bookings', function (Blueprint $table) {
            $table->index('pickup_datetime');
            $table->index(['company_id', 'status_id', 'pickup_datetime'], 'bookings_company_status_pickup_idx');
        });

        Schema::table('drivers', function (Blueprint $table) {
            $table->index('status');
        });

        Schema::table('vehicles', function (Blueprint $table) {
            $table->index('status');
        });

        Schema::table('users', function (Blueprint $table) {
            $table->index('status');
        });
    }

    public function down(): void
    {
        Schema::table('bookings', function (Blueprint $table) {
            $table->dropIndex(['pickup_datetime']);
            $table->dropIndex('bookings_company_status_pickup_idx');
        });

        Schema::table('drivers', function (Blueprint $table) {
            $table->dropIndex(['status']);
        });

        Schema::table('vehicles', function (Blueprint $table) {
            $table->dropIndex(['status']);
        });

        Schema::table('users', function (Blueprint $table) {
            $table->dropIndex(['status']);
        });
    }
};
