<?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::create('users', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->bigInteger('created_time');
            $table->integer('tenant_id');
            $table->uuid('customer_id');
            $table->string('email')->unique();
            $table->string('password')->nullable();
            $table->string('authority', 50);
            $table->string('first_name')->nullable();
            $table->string('last_name')->nullable();
            $table->string('phone', 20)->nullable();
            $table->integer('version');
            $table->string('name');
            $table->text('description')->nullable();
            $table->uuid('default_dashboard_id')->nullable();
            $table->boolean('default_dashboard_fullscreen')->default(false);
            $table->uuid('home_dashboard_id')->nullable();
            $table->boolean('home_dashboard_hide_toolbar')->default(true);
            $table->boolean('user_credentials_enabled')->default(true);
            $table->integer('failed_login_attempts')->default(0);
            $table->bigInteger('last_login_ts')->nullable();

            // Foreign keys
            // $table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('cascade');
            // $table->foreign('customer_id')->references('id')->on('customers')->onDelete('cascade');

            $table->timestamps();
        });

    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('users');
        Schema::dropIfExists('password_reset_tokens');
        Schema::dropIfExists('sessions');
    }
};
