<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     * Membuat tabel 'news' tanpa kolom 'title'.
     */
    public function up(): void
    {
        Schema::create('news', function (Blueprint $table) {
            $table->id();
            
            // Foreign Key ke tabel 'campuses'
            $table->foreignId('campus_id')->constrained('campuses')->onDelete('cascade'); 
            
            // Kolom 'title' dihapus
            
            // Kolom 'excerpt' dijadikan Wajib jika tidak ada 'title'
            $table->text('excerpt'); 
            
            $table->longText('content');
            $table->string('image_url')->nullable();
            $table->string('category', 50)->nullable();
            $table->string('color', 20)->default('blue'); 
            
            $table->timestamp('published_at')->nullable(); 
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade'); 
            
            $table->timestamps();
            
            $table->index(['campus_id', 'published_at']);
        });
    }

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