<?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('flux_cms_blog_posts', function (Blueprint $table) {
            $table->id();
            $table->string('domain_key')->index();
            $table->json('title'); // Übersetzbarer Titel
            $table->json('excerpt')->nullable(); // Übersetzbarer Kurztext
            $table->json('content'); // Übersetzbarer Haupttext
            $table->json('meta_description')->nullable(); // SEO
            $table->json('meta_keywords')->nullable(); // SEO
            $table->json('og_image')->nullable(); // Open Graph Image
            $table->json('settings')->nullable(); // Post-spezifische Einstellungen
            $table->boolean('is_published')->default(false);
            $table->boolean('is_featured')->default(false);
            $table->timestamp('published_at')->nullable();
            $table->string('author_type')->nullable(); // Polymorphic relation type
            $table->unsignedBigInteger('author_id')->nullable(); // Polymorphic relation id
            $table->timestamps();

            // Indexes
            $table->index(['domain_key', 'is_published']);
            $table->index(['domain_key', 'is_published', 'published_at']);
            $table->index(['domain_key', 'is_featured']);
            $table->index(['author_type', 'author_id']);
        });
    }

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