<?php

namespace App\Events;

class DeleteUnverifiedUser
{
    public $userId;

    public function __construct($userId)
    {
        $this->userId = $userId;
    }

    public static function deleteAfterTimeout($userId)
    {
        $model = new self();

        // Define the timeout period
        $timeoutPeriod = 24 * 60 * 60; // 1 day in seconds

        // Retrieve the user's record
        $user = $model->find($userId);

        if ($user) {
            // Get the most recent timestamp to compare with the current time
            $lastActivityTime = strtotime($user['updated_at'] ?? $user['created_at']);

            // Calculate the time difference
            $timeSinceLastActivity = time() - $lastActivityTime;

            // Check if the time difference exceeds the timeout period
            if ($timeSinceLastActivity > $timeoutPeriod) {
                // Delete the user record
                return $model->delete($userId);
            } else {
                // Timeout period has not yet passed
                return false; // Or you can return a message indicating no action taken
            }
        }

        // Return false if the user is not found
        return false;
    }

}

