<?php

declare(strict_types=1);

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

return new class extends Migration
{
    public function up(): void
    {
        if (Schema::hasColumn('dberp_system_profile', 'display_timezone')) {
            return;
        }

        $displayTimezone = (string) config('app.display_timezone', 'Asia/Shanghai');

        Schema::table('dberp_system_profile', function (Blueprint $table) use ($displayTimezone): void {
            // SQLite 不支持 after；列位置不影响业务语义。
            $table->string('display_timezone', 64)
                ->default($displayTimezone)
                ->comment('系统统一展示时区（IANA 标识）');
        });
    }

    public function down(): void
    {
        if (! Schema::hasColumn('dberp_system_profile', 'display_timezone')) {
            return;
        }

        Schema::table('dberp_system_profile', function (Blueprint $table): void {
            $table->dropColumn('display_timezone');
        });
    }
};
