<?php

namespace ModernFields\FieldGroups\Repositories;

use ModernFields\FieldGroups\Entities\User;


/**
 * User Repository
 * 
 * This class is responsible for retrieving user data from the database.
 * 
 * @since 1.0.0
 */
class UserRepository
{
  /**
   * Get a user by their ID.
   * 
   * @param int $user_id The ID of the user to retrieve.
   * @return User|null The user object if found, null otherwise.
   */
  public static function getUserById($user_id): ?User
  {
    $user = get_userdata($user_id);

    if (!$user) {
      return null;
    }

    return new User($user);
  }

  /**
   * Get the current logged-in user.
   * 
   * @return User|null The user object if found, null otherwise.
   */
  public static function getCurrentLoggedInUser(): ?User
  {
    return self::getUserById(get_current_user_id());
  }
}
