def METHOD_NAME(account_index: int, ss58_format: int = 42) -> str:
    """
    Encodes an AccountIndex to an Substrate address according to provided address_type
    Parameters
    ----------
    account_index
    ss58_format
    Returns
    -------
    str
    """
    if 0 <= account_index <= 2 ** 8 - 1:
        account_idx_encoder = RuntimeConfiguration().create_scale_object('u8')
    elif 2 ** 8 <= account_index <= 2 ** 16 - 1:
        account_idx_encoder = RuntimeConfiguration().create_scale_object('u16')
    elif 2 ** 16 <= account_index <= 2 ** 32 - 1:
        account_idx_encoder = RuntimeConfiguration().create_scale_object('u32')
    elif 2 ** 32 <= account_index <= 2 ** 64 - 1:
        account_idx_encoder = RuntimeConfiguration().create_scale_object('u64')
    else:
        raise ValueError("Value too large for an account index")
    return ss58_encode(account_idx_encoder.encode(account_index).data, ss58_format)