<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::disableForeignKeyConstraints();

        Schema::create('news_paragraphs', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('news_id')->index();
            $table->foreign('news_id')->references('id')->on('news')->comment("關聯文章");
            $table->unsignedTinyInteger('paragraph_type')->comment('段落類型 1.images 2.text 3.video');
            $table->json('text_content')->nullable()->comment("文字段落");
            $table->integer("video_type")->nullable();
            $table->string("video_img")->nullable();
            $table->json('video_img_alt')->nullable()->comment("圖片註釋");
            $table->string("link")->nullable();
            $table->string("video_url")->nullable();
            $table->unsignedInteger('order')->default(0)->comment("排序");
        });

        Schema::enableForeignKeyConstraints();
    }

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