You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: mentor_management.rb
    path of file: ./repos/expertiza/app/models
    
    the code of the file until where you have to start completion: class MentorManagement
  # Select a mentor using the following algorithm
  #
  # 1) Find all assignment participants for the
  #    assignment with id [assignment_id] whose
  #    duty is the same as [Particpant#DUTY_MENTOR].
  # 2) Count the number of teams those participants
  #    are a part of, acting as a proxy for the
  #    number of teams they mentor.
  # 3) Return the mentor with the fewest number of
  #    teams they're currently mentoring.
  #
  # This method's runtime is O(n lg n) due to the call to
  # Hash#sort_by. This assertion assumes that the
  # database management system is capable of fetching the
  # required rows at least as quickly.
  #
  # Implementation detail: Any tie between the top 2
  # mentors is decided by the Hash#sort_by algorithm.
  #
  # @return The id of the mentor with the f
    
  def self.assign_mentor(assignment_id, team_id)
    assignment = Assignment.find(assignment_id)
    team = Team.find(team_id)

    # RuboCop 'use guard clause instead of nested conditionals'
    # return if assignments can't accept mentors
    return unless assignment.auto_assign_mentor

    # RuboCop 'use guard clause instead of nested conditionals'
    # return if the assignment or team already have a topic
    return if assignment.topics? || !team.topic.nil?

    curr_team_size = Team.size(team_id)
    max_team_members = Assignment.find(assignment_id).max_team_size

    # RuboCop 'use guard clause instead of nested conditionals'
    # return if the team size hasn't reached > 50% of capacity
    return if curr_team_size * 2 <= max_team_members

    # RuboCop 'use guard clause instead of nested conditionals'
    # return if there's already a mentor in place
    return if team.participants.any? { |participant| participant.can_mentor == true }

    mentor_user = select_mentor(assignment_id)

    # Add the mentor using team model class.
    team_member_added = mentor_user.nil? ? false : team.add_member(mentor_user, assignment_id)

    return unless team_member_added

    notify_team_of_mentor_assignment(mentor_user, team)
  end