import click
from pyproj import CRS as ProjCRS

from geo.core.reader import read_dataset as open_dataset
from geo.core.writer import write_dataset as open_output
from geo.formats import driver_for_path


@click.command()
@click.argument("input_path", type=click.Path(exists=True))
@click.argument("output_path", type=click.Path())
@click.option("--crs", required=True, help="Target CRS (e.g. EPSG:4326, EPSG:3857)")
@click.pass_context
def reproject(ctx, input_path, output_path, crs):
    """Reproject a dataset to a new coordinate reference system."""
    gdf = open_dataset(input_path)
    
    # helper for complex CRS strings if pyproj needed, but geopandas handles most
    # generally we can pass the string directly to to_crs
    gdf = gdf.to_crs(crs)
    
    target_driver = driver_for_path(output_path)
    open_output(gdf, output_path, driver=target_driver)

    if not ctx.obj.get("quiet"):
        click.echo(f"Reprojected {len(gdf)} features → {output_path} [{crs}]", err=True)
