import click


def get_checkpoint(db, id_or_alias):
    """Returns checkpoint entry in `db` indicated by `id_or_alias`.

    Parameters
    ----------
    id_or_alias : str or tuple of str
        Either the ID of the checkpoint, or a tuple of the form (task_name,
        alias) that uniquely points to a checkpoint.

        In the case of the latter, specifying `alias` as `None` will default to
        the entry marked as `default = True` in the index.

    Returns
    -------
    Dict
        Checkpoint data contained in the database.

    """
    if isinstance(id_or_alias, tuple):
        task_name, alias = id_or_alias
        selected = [
            c for c in db['checkpoints']
            if c['task'] == task_name and (
                c['alias'] == alias if alias is not None else c['default']
            )
        ]
    else:
        selected = [c for c in db['checkpoints'] if c['id'] == id_or_alias]

    if len(selected) < 1:
        return None

    if len(selected) > 1:
        click.echo(
            f"Multiple checkpoints found for '{id_or_alias}' "
            f"({len(selected)}). Returning first."
        )

    return selected[0]