<?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::table('projects', function (Blueprint $table) {
            // Add default value for order column
            $table->integer('order')->default(0)->change();

            // Make region_id nullable since it's optional in the form
            $table->foreignId('region_id')->nullable()->change();

            // Make badge_type default to 1 (永續目標)
            $table->tinyInteger('badge_type')->default(1)->change();

            // Make various optional fields nullable
            $table->json('mobile_img_url')->nullable()->change();
            $table->string('thumbnail')->nullable()->change();
            $table->json('summaries')->nullable()->change();
            $table->json('address')->nullable()->change();
            $table->json('floor_plan')->nullable()->change();
            $table->json('building_structure')->nullable()->change();
            $table->json('design_unit')->nullable()->change();
            $table->json('contact_phone')->nullable()->change();
            $table->json('inversment_phone')->nullable()->change();
            $table->json('district')->nullable()->change();
            $table->string('offical_link')->nullable()->change();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('projects', function (Blueprint $table) {
            // Reverse changes - remove defaults and nullable constraints
            $table->integer('order')->change();
            $table->foreignId('region_id')->change();
            $table->tinyInteger('badge_type')->change();
            $table->json('mobile_img_url')->change();
            $table->string('thumbnail')->change();
            $table->json('summaries')->change();
            $table->json('address')->change();
            $table->json('floor_plan')->change();
            $table->json('building_structure')->change();
            $table->json('design_unit')->change();
            $table->json('contact_phone')->change();
            $table->json('inversment_phone')->change();
            $table->json('district')->change();
            $table->string('offical_link')->change();
        });
    }
};
