<?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('patient_login_attempts', function (Blueprint $table) {
            $table->id('id'); // Creates the id column as an auto-incrementing primary key
            $table->unsignedBigInteger('patient_id'); // Define patient_id as an unsigned big integer
            $table->string('phone_number', 20); // Define phone_number as a variable character string with length 20
            $table->string('otp', 10); // Define otp as a variable character string with length 10
            $table->char('partial_ssn', 4); // Define partial_ssn as a fixed-length character string of length 4
            $table->timestampTz('login_attempt_timestamp')->default(now()); // Define login_attempt_timestamp with time zone and default value
            $table->boolean('login_success'); // Define login_success as a boolean
            $table->ipAddress('ip_address')->nullable(); // Define ip_address as an IP address column, allowing null
            $table->decimal('latitude', 9, 6)->nullable(); // Define latitude as a numeric column
            $table->decimal('longitude', 9, 6)->nullable(); // Define longitude as a numeric column
            $table->timestampTz('lockout_timestamp')->nullable(); // Define lockout_timestamp with time zone, allowing null
            
            // Set up the foreign key constraint
            $table->foreign('patient_id')->references('patient_id')->on('patient')->onUpdate('no action')->onDelete('no action');
        });
    }

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