<?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('users', function (Blueprint $table) {
            // Saldo credit internal: 1 credit = 1 klik valid (BR-01).
            $table->unsignedInteger('credit')->default(0)->after('password');
            $table->boolean('active')->default(true)->after('credit');

            // Data registrasi member (FR-AUT-03): nama depan, nama belakang, perusahaan, telepon.
            // `name` (existing) dipakai sebagai nama depan; kita simpan nama belakang terpisah.
            $table->string('first_name')->nullable()->after('name');
            $table->string('last_name')->nullable()->after('first_name');
            $table->string('company')->nullable()->after('last_name');
            $table->string('phone', 32)->nullable()->after('company');
            $table->string('username')->nullable()->unique()->after('email');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn([
                'credit',
                'active',
                'first_name',
                'last_name',
                'company',
                'phone',
                'username',
            ]);
        });
    }
};
