import json


def create_polygon(indexes, title):
    """
    Returns the object dictionary in supervisely format
    Arguments:
        indexes: ndarray of ints (nvertices, 2)
            2D indexes of points of the polygon
        title: string
            The type of the polygon as defined in the project meta

    returns: dict
    """

    #        "classTitle" : "Nucleus",
    template = '''
    {
            "bitmap": null,
            "description": "",
            "points": {
                "interior": []
            },
            "tags": []
    }
    '''
    obj_dict = json.loads(template)

    #Create the list of indexes 
    poly_list = []
    for index in indexes:
        try:
            poly_list.append([int(index[0]), int(index[1])]) 
        except Exception as e:
            print(indexes)
            print(index)
            raise

    obj_dict["points"]["exterior"] = poly_list
    obj_dict["classTitle"] = title
    return obj_dict