def get_restore_user(domain, couch_user, as_user_obj):
    """
    This will retrieve the restore_user from the couch_user or the as_user_obj
    if specified
    :param domain: Domain of restore
    :param couch_user: The couch user attempting authentication
    :param as_user_obj: The user that the couch_user is attempting to get
        a restore user for. If None will get restore of the couch_user.
    :returns: An instance of OTARestoreUser
    """
    couch_restore_user = as_user_obj or couch_user

    if couch_restore_user.is_commcare_user():
        return couch_restore_user.to_ota_restore_user()
    elif couch_restore_user.is_web_user():
        return couch_restore_user.to_ota_restore_user(domain)
    else:
        return None