<?php

declare(strict_types=1);

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->id();
            $table->string('first_name')->nullable();
            $table->string('last_name')->nullable();
            $table->dateTime('avatar_verified_at')->nullable();
            $table->string('avatar')->nullable();
            $table->string('national_code')->nullable()->unique();
            $table->string('national_cart_image')->nullable();
            $table->string('email')->unique()->nullable();
            $table->string('cellphone')->nullable();
            $table->date('dob')->nullable(); // date of birth
            $table->decimal('phone', 11, 0)->nullable();

            // address
            // province_id
            // county_id
            // postal_code
            // lat & lang
            $table->string('password')->nullable();
            $table->boolean('gender')->nullable();
            $table->longText('desc')->nullable();
            $table->timestamp('email_verified_at')->nullable();
            $table->dateTime('last_online_at')->nullable();
            $table->decimal('base_credit', 19, 0)->default(0);
            $table->smallInteger('login_type')->nullable();
            $table->smallInteger('status')->default(1); // 1: active, 0: inactive
            $table->longText('status_desc')->nullable();
            $table->rememberToken();
            $table->softDeletes();
            $table->timestamps();
        });

        Schema::create('password_reset_tokens', function (Blueprint $table) {
            $table->string('email')->primary();
            $table->string('token');
            $table->timestamp('created_at')->nullable();
        });

        Schema::create('sessions', function (Blueprint $table) {
            $table->string('id')->primary();
            $table->foreignId('user_id')->nullable()->index();
            $table->string('ip_address', 45)->nullable();
            $table->text('user_agent')->nullable();
            $table->longText('payload');
            $table->integer('last_activity')->index();
        });
    }

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