<?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('route_articles', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('feed_id');
            $table->unsignedBigInteger('platform_channel_id');
            $table->foreignId('article_id')->constrained()->onDelete('cascade');
            $table->enum('approval_status', ['pending', 'approved', 'rejected'])->default('pending');
            $table->timestamp('validated_at')->nullable();
            $table->timestamps();

            $table->foreign(['feed_id', 'platform_channel_id'])
                ->references(['feed_id', 'platform_channel_id'])
                ->on('routes')
                ->onDelete('cascade');

            $table->unique(['feed_id', 'platform_channel_id', 'article_id'], 'route_articles_unique');
            $table->index(['approval_status', 'created_at']);
        });
    }

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