<?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('rss_feeds', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('feed_url'); // The .xml or .rss url
            $table->foreignId('category_id')->constrained()->onDelete('cascade'); // Assign imported posts to this category
            $table->foreignId('user_id')->constrained(); // Assign author (usually Admin)
            
            // Configuration
            $table->boolean('is_active')->default(true);
            $table->boolean('fetch_full_content')->default(false); // If false, use RSS description
            $table->integer('posts_limit_per_crawl')->default(5);
            $table->enum('status_on_import', ['published', 'pending', 'draft'])->default('pending');
            
            // Filtering
            $table->json('must_contain_keywords')->nullable(); // e.g. ["Bitcoin", "Crypto"]
            $table->json('must_not_contain_keywords')->nullable();
            
            $table->timestamp('last_crawled_at')->nullable();
            $table->timestamps();
        });
    }

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