<?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('tbl_news', function (Blueprint $table) {
            $table->increments('news_id');
            $table->string('news_title', 255);
            $table->string('news_title_english', 255)->nullable();
            $table->mediumText('news_content');
            $table->mediumText('news_content_english')->nullable();
            $table->mediumText('news_content_short')->nullable();
            $table->mediumText('news_content_short_english')->nullable();
            $table->string('photo_url', 255);                              // actual column name in SQL
            $table->dateTime('published_at')->nullable()->index();
            $table->integer('category_id')->unsigned()->index();
            $table->integer('author_id')->unsigned()->nullable()->index();
            $table->string('encode_title', 255)->index();
            $table->string('img_alt', 255)->nullable();
            $table->string('img_alt_english', 255)->nullable();
            $table->string('meta_title', 255)->nullable();
            $table->string('meta_title_english', 255)->nullable();
            $table->mediumText('meta_keyword')->nullable();
            $table->mediumText('meta_keyword_english')->nullable();
            $table->mediumText('meta_description')->nullable();
            $table->mediumText('meta_description_english')->nullable();
            $table->string('type', 50)->default('general');
            $table->unsignedBigInteger('views')->default(0);

            $table->foreign('category_id')->references('category_id')->on('tbl_category');
            $table->foreign('author_id')->references('author_id')->on('tbl_authors')->nullOnDelete();
        });
    }
    public function down(): void { Schema::dropIfExists('tbl_news'); }
};
