# Path: mapchete/index.py
# def zoom_index_gen(
#     mp=None,
#     out_dir=None,
#     zoom=None,
#     tile=None,
#     geojson=False,
#     gpkg=False,
#     shapefile=False,
#     txt=False,
#     vrt=False,
#     fieldname="location",
#     basepath=None,
#     for_gdal=True,
#     threading=False,
#     **kwargs,
# ):
#     """
#     Generate indexes for given zoom level.
# 
#     Parameters
#     ----------
#     mp : Mapchete object
#         process output to be indexed
#     out_dir : path
#         optionally override process output directory
#     zoom : int
#         zoom level to be processed
#     geojson : bool
#         generate GeoJSON index (default: False)
#     gpkg : bool
#         generate GeoPackage index (default: False)
#     shapefile : bool
#         generate Shapefile index (default: False)
#     txt : bool
#         generate tile path list textfile (default: False)
#     vrt : bool
#         GDAL-style VRT file (default: False)
#     fieldname : str
#         field name which contains paths of tiles (default: "location")
#     basepath : str
#         if set, use custom base path instead of output path
#     for_gdal : bool
#         use GDAL compatible remote paths, i.e. add "/vsicurl/" before path
#         (default: True)
#     """
#     if tile and zoom:  # pragma: no cover
#         raise ValueError("tile and zoom cannot be used at the same time")
#     zoom = tile[0] if tile else zoom
#     for zoom in get_zoom_levels(process_zoom_levels=zoom):
#         with ExitStack() as es:
#             # get index writers for all enabled formats
#             index_writers = []
#             if geojson:
#                 index_writers.append(
#                     es.enter_context(
#                         VectorFileWriter(
#                             driver="GeoJSON",
#                             out_path=_index_file_path(out_dir, zoom, "geojson"),
#                             crs=mp.config.output_pyramid.crs,
#                             fieldname=fieldname,
#                         )
#                     )
#                 )
#             if gpkg:
#                 index_writers.append(
#                     es.enter_context(
#                         VectorFileWriter(
#                             driver="GPKG",
#                             out_path=_index_file_path(out_dir, zoom, "gpkg"),
#                             crs=mp.config.output_pyramid.crs,
#                             fieldname=fieldname,
#                         )
#                     )
#                 )
#             if shapefile:
#                 index_writers.append(
#                     es.enter_context(
#                         VectorFileWriter(
#                             driver="ESRI Shapefile",
#                             out_path=_index_file_path(out_dir, zoom, "shp"),
#                             crs=mp.config.output_pyramid.crs,
#                             fieldname=fieldname,
#                         )
#                     )
#                 )
#             if txt:
#                 index_writers.append(
#                     es.enter_context(
#                         TextFileWriter(out_path=_index_file_path(out_dir, zoom, "txt"))
#                     )
#                 )
#             if vrt:
#                 index_writers.append(
#                     es.enter_context(
#                         VRTFileWriter(
#                             out_path=_index_file_path(out_dir, zoom, "vrt"),
#                             output=mp.config.output,
#                             out_pyramid=mp.config.output_pyramid,
#                         )
#                     )
#                 )
# 
#             logger.debug("use the following index writers: %s", index_writers)
# 
#             if tile:
#                 output_tiles_batches = mp.config.output_pyramid.tiles_from_bounds(
#                     mp.config.process_pyramid.tile(*tile).bounds, zoom, batch_by="row"
#                 )
#             else:
#                 output_tiles_batches = mp.config.output_pyramid.tiles_from_geom(
#                     mp.config.area_at_zoom(zoom), zoom, batch_by="row"
#                 )
# 
#             for output_tile, exists in tiles_exist(
#                 mp.config, output_tiles_batches=output_tiles_batches
#             ):
# 
#                 tile_path = _tile_path(
#                     orig_path=mp.config.output.get_path(output_tile),
#                     basepath=basepath,
#                     for_gdal=for_gdal,
#                 )
#                 # get indexes where tile entry does not exist
#                 indexes = [
#                     index_writer
#                     for index_writer in index_writers
#                     if not index_writer.entry_exists(tile=output_tile, path=tile_path)
#                 ]
# 
#                 if indexes and exists:
#                     logger.debug("%s exists", tile_path)
#                     logger.debug("write to %s indexes", len(indexes))
#                     for index in indexes:
#                         index.write(output_tile, tile_path)
# 
#                 # yield tile for progress information
#                 yield output_tile


import logging
import mapchete
from typing import Callable, List, Tuple, Union
from rasterio.crs import CRS
from shapely.geometry.base import BaseGeometry
from mapchete.index import zoom_index_gen
    """

    if not any([geojson, gpkg, shp, txt, vrt]):
        raise ValueError(
            """At least one of '--geojson', '--gpkg', '--shp', '--vrt' or '--txt'"""
            """must be provided."""
        )

    def _empty_callback(*_):
        pass

    msg_callback = msg_callback or _empty_callback
    fs_opts = fs_opts or {}

    msg_callback(f"create index(es) for {tiledir}")
    # process single tile
    with mapchete.open(
        tiledir,
        mode="readonly",
        fs_kwargs=fs_opts,
        zoom=tile[0] if tile else zoom,
        point=point,
        point_crs=point_crs,
        bounds=bounds,
        bounds_crs=bounds_crs,
        area=area,
        area_crs=area_crs,
    ) as mp:

        return mapchete.Job(

# Path: mapchete/index.py
# def zoom_index_gen(
#     mp=None,
#     out_dir=None,
#     zoom=None,
#     tile=None,
#     geojson=False,
#     gpkg=False,
#     shapefile=False,
#     txt=False,
#     vrt=False,
#     fieldname="location",
#     basepath=None,
#     for_gdal=True,
#     threading=False,
#     **kwargs,
# ):
#     """
#     Generate indexes for given zoom level.
# 
#     Parameters
#     ----------
#     mp : Mapchete object
#         process output to be indexed
#     out_dir : path
#         optionally override process output directory
#     zoom : int
#         zoom level to be processed
#     geojson : bool
#         generate GeoJSON index (default: False)
#     gpkg : bool
#         generate GeoPackage index (default: False)
#     shapefile : bool
#         generate Shapefile index (default: False)
#     txt : bool
#         generate tile path list textfile (default: False)
#     vrt : bool
#         GDAL-style VRT file (default: False)
#     fieldname : str
#         field name which contains paths of tiles (default: "location")
#     basepath : str
#         if set, use custom base path instead of output path
#     for_gdal : bool
#         use GDAL compatible remote paths, i.e. add "/vsicurl/" before path
#         (default: True)
#     """
#     if tile and zoom:  # pragma: no cover
#         raise ValueError("tile and zoom cannot be used at the same time")
#     zoom = tile[0] if tile else zoom
#     for zoom in get_zoom_levels(process_zoom_levels=zoom):
#         with ExitStack() as es:
#             # get index writers for all enabled formats
#             index_writers = []
#             if geojson:
#                 index_writers.append(
#                     es.enter_context(
#                         VectorFileWriter(
#                             driver="GeoJSON",
#                             out_path=_index_file_path(out_dir, zoom, "geojson"),
#                             crs=mp.config.output_pyramid.crs,
#                             fieldname=fieldname,
#                         )
#                     )
#                 )
#             if gpkg:
#                 index_writers.append(
#                     es.enter_context(
#                         VectorFileWriter(
#                             driver="GPKG",
#                             out_path=_index_file_path(out_dir, zoom, "gpkg"),
#                             crs=mp.config.output_pyramid.crs,
#                             fieldname=fieldname,
#                         )
#                     )
#                 )
#             if shapefile:
#                 index_writers.append(
#                     es.enter_context(
#                         VectorFileWriter(
#                             driver="ESRI Shapefile",
#                             out_path=_index_file_path(out_dir, zoom, "shp"),
#                             crs=mp.config.output_pyramid.crs,
#                             fieldname=fieldname,
#                         )
#                     )
#                 )
#             if txt:
#                 index_writers.append(
#                     es.enter_context(
#                         TextFileWriter(out_path=_index_file_path(out_dir, zoom, "txt"))
#                     )
#                 )
#             if vrt:
#                 index_writers.append(
#                     es.enter_context(
#                         VRTFileWriter(
#                             out_path=_index_file_path(out_dir, zoom, "vrt"),
#                             output=mp.config.output,
#                             out_pyramid=mp.config.output_pyramid,
#                         )
#                     )
#                 )
# 
#             logger.debug("use the following index writers: %s", index_writers)
# 
#             if tile:
#                 output_tiles_batches = mp.config.output_pyramid.tiles_from_bounds(
#                     mp.config.process_pyramid.tile(*tile).bounds, zoom, batch_by="row"
#                 )
#             else:
#                 output_tiles_batches = mp.config.output_pyramid.tiles_from_geom(
#                     mp.config.area_at_zoom(zoom), zoom, batch_by="row"
#                 )
# 
#             for output_tile, exists in tiles_exist(
#                 mp.config, output_tiles_batches=output_tiles_batches
#             ):
# 
#                 tile_path = _tile_path(
#                     orig_path=mp.config.output.get_path(output_tile),
#                     basepath=basepath,
#                     for_gdal=for_gdal,
#                 )
#                 # get indexes where tile entry does not exist
#                 indexes = [
#                     index_writer
#                     for index_writer in index_writers
#                     if not index_writer.entry_exists(tile=output_tile, path=tile_path)
#                 ]
# 
#                 if indexes and exists:
#                     logger.debug("%s exists", tile_path)
#                     logger.debug("write to %s indexes", len(indexes))
#                     for index in indexes:
#                         index.write(output_tile, tile_path)
# 
#                 # yield tile for progress information
#                 yield output_tile


# Path: mapchete/commands/_index.py
import logging
import mapchete
from typing import Callable, List, Tuple, Union
from rasterio.crs import CRS
from shapely.geometry.base import BaseGeometry
from mapchete.index import zoom_index_gen

    """

    if not any([geojson, gpkg, shp, txt, vrt]):
        raise ValueError(
            """At least one of '--geojson', '--gpkg', '--shp', '--vrt' or '--txt'"""
            """must be provided."""
        )

    def _empty_callback(*_):
        pass

    msg_callback = msg_callback or _empty_callback
    fs_opts = fs_opts or {}

    msg_callback(f"create index(es) for {tiledir}")
    # process single tile
    with mapchete.open(
        tiledir,
        mode="readonly",
        fs_kwargs=fs_opts,
        zoom=tile[0] if tile else zoom,
        point=point,
        point_crs=point_crs,
        bounds=bounds,
        bounds_crs=bounds_crs,
        area=area,
        area_crs=area_crs,
    ) as mp:

        return mapchete.Job(

            zoom_index_gen,