<?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_recommendations', function (Blueprint $table) {
            $table->id();
            $table->foreignId('page_id')->constrained()->onDelete('cascade');
            $table->string('keyword');
            $table->boolean('is_primary')->default(false);
            $table->decimal('composite_score', 5, 2)->default(0);
            $table->decimal('ai_relevance_score', 5, 2)->default(0);
            $table->integer('search_volume')->nullable();
            $table->string('competition')->nullable(); // LOW, MEDIUM, HIGH
            $table->integer('competition_index')->nullable(); // 0-100
            $table->decimal('cpc', 8, 2)->nullable();
            $table->string('intent')->nullable(); // informational, commercial, transactional, navigational
            $table->text('reasoning')->nullable();
            $table->timestamps();

            $table->index(['page_id', 'is_primary']);
            $table->index('keyword');
        });
    }

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