<?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::table('contacts', fn (Blueprint $table) => $table->index(['business_id', 'contact_owner_id', 'status', 'created_at'], 'contacts_list_idx'));
        Schema::table('leads', fn (Blueprint $table) => $table->index(['business_id', 'contact_owner_id', 'status', 'moved_at', 'created_at'], 'leads_list_idx'));
        Schema::table('deals', fn (Blueprint $table) => $table->index(['business_id', 'owner_id', 'status', 'created_at'], 'deals_list_idx'));
        Schema::table('tickets', fn (Blueprint $table) => $table->index(['business_id', 'contact_owner_id', 'moved_at', 'created_at'], 'tickets_list_idx'));
        Schema::table('products', fn (Blueprint $table) => $table->index(['business_id', 'owner_id', 'created_at'], 'products_list_idx'));
        Schema::table('campaigns', fn (Blueprint $table) => $table->index(['business_id', 'owner_id', 'created_at'], 'campaigns_list_idx'));
        Schema::table('messages', fn (Blueprint $table) => $table->index(['business_id', 'created_at'], 'messages_list_idx'));
        Schema::table('surveys', fn (Blueprint $table) => $table->index(['business_id', 'status', 'created_at'], 'surveys_list_idx'));
    }

    public function down(): void
    {
        Schema::table('contacts', fn (Blueprint $table) => $table->dropIndex('contacts_list_idx'));
        Schema::table('leads', fn (Blueprint $table) => $table->dropIndex('leads_list_idx'));
        Schema::table('deals', fn (Blueprint $table) => $table->dropIndex('deals_list_idx'));
        Schema::table('tickets', fn (Blueprint $table) => $table->dropIndex('tickets_list_idx'));
        Schema::table('products', fn (Blueprint $table) => $table->dropIndex('products_list_idx'));
        Schema::table('campaigns', fn (Blueprint $table) => $table->dropIndex('campaigns_list_idx'));
        Schema::table('messages', fn (Blueprint $table) => $table->dropIndex('messages_list_idx'));
        Schema::table('surveys', fn (Blueprint $table) => $table->dropIndex('surveys_list_idx'));
    }
};
