<?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::table('users', function (Blueprint $table) {
            $table->string('firebase_uid')->nullable()->unique()->after('email');
            $table->string('business_name')->nullable()->after('firebase_uid');
            $table->string('phone')->nullable()->after('business_name');
            $table->string('avatar')->nullable()->after('phone');
            $table->boolean('is_admin')->default(false)->after('avatar');
            $table->boolean('is_banned')->default(false)->after('is_admin');
            $table->string('plan')->default('free')->after('is_banned'); // free|starter|growth|pro
            $table->timestamp('plan_expires_at')->nullable()->after('plan');
            $table->string('plan_source')->default('iap')->after('plan_expires_at'); // iap|voucher|stripe|paypal
            $table->bigInteger('storage_used_bytes')->default(0)->after('plan_source');
            $table->string('country_code', 5)->nullable()->after('storage_used_bytes');
            $table->string('currency_code', 5)->default('USD')->after('country_code');
            $table->timestamp('last_seen_at')->nullable()->after('currency_code');

            $table->index('firebase_uid');
            $table->index('plan');
            $table->index('is_admin');
        });
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn([
                'firebase_uid','business_name','phone','avatar','is_admin','is_banned',
                'plan','plan_expires_at','plan_source','storage_used_bytes',
                'country_code','currency_code','last_seen_at',
            ]);
        });
    }
};
