<?php

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

class CreateUsersTable extends Migration
{
    public function up(): void
    {
        Schema::create('users', function (Blueprint $table) {
            $table->uuid('id')->primary(); // Use UUID primary key

            $table->string('name');
            $table->string('email')->unique();
            $table->string('phone')->unique();

            // Store password as a hashed string (handled in the controller logic)
            $table->string('password');

            $table->string('state')->nullable();
            $table->string('status')->default('inactive');

            $table->boolean('email_ver')->default(false);
            $table->timestamp('email_ver_at')->nullable();

            $table->boolean('phone_ver')->default(false);
            $table->timestamp('phone_ver_at')->nullable();

            $table->string('otp')->nullable();
            $table->timestamp('otp_ver_at')->nullable();

            $table->integer('invalid_pin_tries')->default(0);
            $table->timestamp('invalid_pin_tries_at')->nullable();

            $table->rememberToken(); // Optional but useful for auth
            $table->timestamps(); // created_at and updated_at
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('users');
    }
}
