import pyogrio

from geo.formats import driver_for_path, validate_writable


def write_dataset(gdf, path: str, driver: str | None = None, **kwargs):
    """Write a GeoDataFrame to a file using Pyogrio.

    Args:
        gdf: GeoDataFrame to write.
        path: Output file path.
        driver: OGR driver name. Auto-detected from extension if None.
    """
    if driver is None:
        driver = driver_for_path(path)
    validate_writable(driver)
    
    pyogrio.write_dataframe(gdf, path, driver=driver, **kwargs)
