from typing import OrderedDict


def gen_top(service_uri, no_pages, num_mem, label=None):
    """
    Generate the top level collection page.

    :param service_uri: base uri for the AS paged site.
    :param no_pages:
    :param num_mem:
    :param label:
    :return: dict
    """
    top = OrderedDict()
    top['@context'] = [
                "http://iiif.io/api/presentation/2/context.json",
                "https://www.w3.org/ns/activitystreams"
            ]
    top['id'] = service_uri
    top['type'] = 'OrderedCollection'
    if label:
        top['label'] = label
    top['total'] = num_mem
    top['first'] = {'id': service_uri + str(1), 'type': 'OrderedCollectionPage'}
    top['last'] = {'id': service_uri + str(no_pages), 'type': 'OrderedCollectionPage'}
    return top