<?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('tracking_searches', function (Blueprint $table) {
            $table->id();
            
            // Common fields
            $table->string('device_id');
            $table->text('user_agent')->nullable();
            $table->string('ip_address')->nullable();
            $table->enum('platform', ['web', 'ios', 'android'])->default('web');
            
            // Search-specific fields
            $table->enum('search_type', ['meme', 'background']);
            $table->text('search_query');
            $table->json('search_filters')->nullable();
            
            // Timestamps
            $table->timestamp('action_at');
            $table->timestamps();
            
            // Indexes
            $table->index(['device_id', 'action_at']);
            $table->index(['search_type', 'action_at']);
            $table->index('platform');
        });
    }

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