# typed: true
module Domain::Users::FaUsersHelper
  extend T::Sig
  include HelpersInterface

  # TODO - remove this once we've migrated similarity scores to new user model
  sig do
    params(
      user: Domain::User::FaUser,
      limit: Integer,
      exclude_followed_by: T.nilable(Domain::User::FaUser),
    ).returns(T::Array[Domain::User::FaUser])
  end
  def similar_users_by_followed(user, limit: 10, exclude_followed_by: nil)
    factors = Domain::Factors::UserUserFollowToFactors.find_by(user: user)
    return [] if factors.nil?

    relation =
      Domain::NeighborFinder
        .find_neighbors(factors)
        .limit(limit)
        .includes(:user)
    if exclude_followed_by
      relation =
        relation.where.not(
          user_id: exclude_followed_by.followed_users.select(:to_id),
        )
    end

    relation.map { |factor| factor.user }
  end
end
