@classmethod<EOL><INDENT>def enroll_users_in_program(cls, enterprise_customer, program_details, course_mode, emails, cohort=None):<DEDENT>
existing_users, unregistered_emails = cls.get_users_by_email(emails)<EOL>course_ids = get_course_runs_from_program(program_details)<EOL>successes = []<EOL>pending = []<EOL>failures = []<EOL>for user in existing_users:<EOL><INDENT>succeeded = cls.enroll_user(enterprise_customer, user, course_mode, *course_ids)<EOL>if succeeded:<EOL><INDENT>successes.append(user)<EOL><DEDENT>else:<EOL><INDENT>failures.append(user)<EOL><DEDENT><DEDENT>for email in unregistered_emails:<EOL><INDENT>pending_user = enterprise_customer.enroll_user_pending_registration(<EOL>email,<EOL>course_mode,<EOL>*course_ids,<EOL>cohort=cohort<EOL>)<EOL>pending.append(pending_user)<EOL><DEDENT>return successes, pending, failures<EOL>
Enroll existing users in all courses in a program, and create pending enrollments for nonexisting users.

Args:
    enterprise_customer: The EnterpriseCustomer which is sponsoring the enrollment
    program_details: The details of the program in which we're enrolling
    course_mode (str): The mode with which we're enrolling in the program
    emails: An iterable of email addresses which need to be enrolled

Returns:
    successes: A list of users who were successfully enrolled in all courses of the program
    pending: A list of PendingEnterpriseCustomerUsers who were successfully linked and had
        pending enrollments created for them in the database
    failures: A list of users who could not be enrolled in the program