<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        Schema::create('contents', function (Blueprint $table) {
            $table->id();

            // Basic Information
            $table->string('title');
            $table->string('title_en');
            $table->string('title_ar');
            $table->string('slug')->unique();
            $table->text('short_description')->nullable();
            $table->text('short_description_en')->nullable();
            $table->text('short_description_ar')->nullable();
            $table->longText('description')->nullable();
            $table->longText('description_en')->nullable();
            $table->longText('description_ar')->nullable();
            $table->longText('content')->nullable(); // Full content/body
            $table->longText('content_en')->nullable(); // Full content/body
            $table->longText('content_ar')->nullable(); // Full content/body

            // URL and Meta Information
            $table->string('url')->nullable(); // Custom URL if different from slug
            $table->string('meta_title')->nullable();
            $table->text('meta_description')->nullable();
            $table->text('meta_keywords')->nullable(); // Comma-separated keywords
            $table->string('canonical_url')->nullable(); // For SEO

            // Islamic Content Specific
            $table->text('ayat')->nullable(); // Quranic verses
            $table->text('ayat_en')->nullable(); // Quranic verses
            $table->text('ayat_ar')->nullable(); // Quranic verses
            $table->string('surah_name_en')->nullable(); // Surah name
            $table->string('surah_name_ar')->nullable(); // Surah name
            $table->integer('ayat_number')->nullable(); // Verse number
            $table->integer('ayat_number_en')->nullable(); // Verse number
            $table->integer('ayat_number_ar')->nullable(); // Verse number
            $table->text('hadith')->nullable(); // Hadith text
            $table->text('hadith_en')->nullable(); // Hadith text
            $table->text('hadith_ar')->nullable(); // Hadith text
            $table->string('hadith_reference')->nullable(); // Hadith reference
            $table->string('hadith_reference_en')->nullable(); // Hadith reference
            $table->string('hadith_reference_ar')->nullable(); // Hadith reference
            $table->text('tafsir_en')->nullable(); // Tafsir/Explanation
            $table->text('tafsir_ar')->nullable(); // Tafsir/Explanation
            $table->string('reference')->nullable(); // General reference
            $table->string('reference_en')->nullable(); // General reference
            $table->string('reference_ar')->nullable(); // General reference
            $table->string('scholar_name')->nullable(); // Scholar name for references
            $table->string('scholar_name_en')->nullable(); // Scholar name for references
            $table->string('scholar_name_ar')->nullable(); // Scholar name for references

            // Media
            $table->string('featured_image')->nullable();
            $table->string('thumbnail_image')->nullable();
            $table->json('gallery_images')->nullable(); // Multiple images
            $table->string('video_url')->nullable(); // YouTube/Vimeo URL
            $table->string('audio_url')->nullable(); // Audio file/recitation
            $table->string('pdf_url')->nullable(); // PDF document

            // Relations
            $table->foreignId('category_id')->nullable()->constrained()->onDelete('set null');
            $table->foreignId('author_id')->nullable()->constrained('users')->onDelete('set null');

            // Status and Settings
            $table->enum('status', ['draft', 'published', 'archived'])->default('draft');
            $table->enum('content_type', [
                'activity',
                'article',
                'blog',
                'news',
                'event',
                'fatwa',
                'lecture',
                'quran_verse',
                'hadith',
                'dua',
                'story'
            ])->default('article');

            $table->boolean('is_featured')->default(false);
            $table->boolean('is_trending')->default(false);
            $table->boolean('is_breaking')->default(false); // For news
            $table->boolean('allow_comments')->default(true);
            $table->integer('view_count')->default(0);
            $table->integer('like_count')->default(0);
            $table->integer('share_count')->default(0);

            // SEO and Sharing
            $table->string('og_title')->nullable(); // Open Graph title
            $table->text('og_description')->nullable(); // Open Graph description
            $table->string('og_image')->nullable(); // Open Graph image
            $table->string('twitter_title')->nullable();
            $table->text('twitter_description')->nullable();
            $table->string('twitter_image')->nullable();

            // Scheduling
            $table->timestamp('published_at')->nullable();
            $table->timestamp('expires_at')->nullable(); // For time-sensitive content

            // Additional Fields
            $table->json('custom_fields')->nullable(); // For flexible additional data
            $table->string('language')->default('bn'); // bn, en, ar
            $table->integer('reading_time')->nullable(); // In minutes

            $table->timestamps();
            $table->softDeletes(); // For trash functionality

            // Indexes for performance
            $table->index('slug');
            $table->index('status');
            $table->index('content_type');
            $table->index('category_id');
            $table->index('author_id');
            $table->index('published_at');
            $table->index(['status', 'published_at']);
        });
    }

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