import click


def get_checkpoint_by_class(db, class_path):
    """Returns checkpoint entry in `db` indicated by `class_path`.

    Parameters
    ----------
    class_path : str
        Fully specified path to class (e.g. `terran.pose.openpose.OpenPose`)
        of the model to get the checkpoint for.

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

    """
    selected = [c for c in db['checkpoints'] if c['class'] == class_path]

    if len(selected) < 1:
        return None

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

    return selected[0]