<?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('platform_settings', function (Blueprint $t) {
            $t->id();
            $t->string('key', 100)->unique();
            $t->json('value')->nullable();
            $t->timestamps();
        });

        Schema::table('plans', function (Blueprint $t) {
            $t->boolean('is_demo')->default(false)->after('is_public');
            $t->integer('trial_days')->nullable()->after('is_demo')
                ->comment('Days of free trial for tenants on this plan (null = no trial)');
        });

        Schema::table('companies', function (Blueprint $t) {
            $t->boolean('is_demo')->default(false)->after('plan_id')
                ->comment('Demo tenant — features unlocked but data may be reset');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('platform_settings');
        Schema::table('plans', fn (Blueprint $t) => $t->dropColumn(['is_demo', 'trial_days']));
        Schema::table('companies', fn (Blueprint $t) => $t->dropColumn('is_demo'));
    }
};
