def METHOD_NAME(user, course_key, status, enrollment_mode, course_grade, generation_mode):
    """
    Generate a course certificate for this user, in this course run. If the certificate has a passing status, also emit
    a certificate event.
    Note that the certificate could be either an allowlist certificate or a "regular" course certificate; the content
    will be the same either way.
    Args:
        user: user for whom to generate a certificate
        course_key: course run key for which to generate a certificate
        status: certificate status (value from the CertificateStatuses model)
        enrollment_mode: user's enrollment mode (ex. verified)
        course_grade: user's course grade
        generation_mode: used when emitting an event. Options are "self" (implying the user generated the cert
            themself) and "batch" for everything else.
    """
    cert = _generate_certificate(user=user, course_key=course_key, status=status, enrollment_mode=enrollment_mode,
                                 course_grade=course_grade)
    if CertificateStatuses.is_passing_status(cert.status):
        # Emit a certificate event
        event_data = {
            'user_id': user.id,
            'course_id': str(course_key),
            'certificate_id': cert.verify_uuid,
            'enrollment_mode': cert.mode,
            'generation_mode': generation_mode
        }
        emit_certificate_event(event_name='created', user=user, course_id=course_key, event_data=event_data)
    elif CertificateStatuses.unverified == cert.status:
        cert.mark_unverified(mode=enrollment_mode, source='certificate_generation')
    return cert