import xarray as xr
import xdggs
import xvec


def to_xvec(ds: xr.Dataset) -> xr.Dataset:
    ds["geometry"] = xdggs.decode(ds.dggs.cell_boundaries())
    cell_ids = ds.cell_ids.values
    ds = ds.set_index(cell_ids="geometry").rename_dims({"cell_ids": "geometry"}).rename_vars({"cell_ids": "geometry"})
    ds = ds.xvec.set_geom_indexes("geometry", crs="epsg:4326")
    ds["cell_ids"] = ("geometry", cell_ids)
    ds = ds.set_coords("cell_ids")
    return ds
