<?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('keyword_metrics_cache', function (Blueprint $table) {
            $table->id();
            $table->string('keyword_hash', 32); // MD5 hash
            $table->string('keyword');
            $table->integer('location_code')->default(2840);
            $table->integer('search_volume')->default(0);
            $table->string('competition')->nullable();
            $table->integer('competition_index')->nullable();
            $table->decimal('cpc', 8, 2)->nullable();
            $table->timestamp('fetched_at');
            $table->timestamp('expires_at')->index();

            $table->unique(['keyword_hash', 'location_code']);
            $table->index('keyword');
        });
    }

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