import json


def prepare_lists(path_lists):
    """
    Parse evaluation lists (i.e., probe and gallery lists)
    """
    path_gallery = path_lists.joinpath("gallery.json")
    path_probes = path_lists.joinpath("probes.json")
    path_gt = path_lists.joinpath("true_relatives.json")

    with open(path_gallery) as f:
        gallery = json.load(f)
    gallery.sort()
    gallery = [
        (i, g.split("/")[0], "/".join(g.split("/")[:2]), g)
        for i, g in enumerate(gallery)
    ]

    with open(path_probes) as f:
        probes = json.load(f)

    with open(path_gt) as f:
        groundtruth = json.load(f)
    fid_list = list(probes.keys())
    fid_list.sort()
    probes = [(fid, probes[fid], groundtruth[fid]) for fid in fid_list]

    return gallery, probes, fid_list