<?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('serp_urls', function (Blueprint $table) {
            $table->id();
            $table->foreignId('news_serp_result_id');
            $table->foreignId('category_id')->nullable();
            $table->string('category_name')->nullable();
            $table->string('source')->default('serp');
            $table->string('url');
            $table->string('country_iso');
            $table->string('title')->nullable();
            $table->text('description')->nullable();
            $table->boolean('picked')->default(false);
            $table->boolean('processed')->default(false);
            $table->boolean('crawled')->default(false);
            $table->boolean('written')->default(false);
            $table->json('suggestion_data')->nullable();
            $table->datetime('url_posted_at');
            $table->timestamp('serp_at')->nullable();
            $table->enum('status', ['initial', 'processing', 'complete', 'failed', 'blocked', 'limited'])->default('initial');
            $table->tinyInteger('process_status')->nullable();
            $table->timestamps();

            $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
            $table->foreign('news_serp_result_id')->references('id')->on('news_serp_results')->onDelete('cascade');
        });
    }

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