"""ZFS operations."""

from __future__ import annotations

from .runner import run


def dataset_exists(
    name: str,
    *,
    log_file: str | None = None,
    dry_run: bool = False,
) -> bool:
    result = run(
        ["zfs", "list", "-H", "-o", "name", name],
        allow_fail=True,
        log_file=log_file,
        dry_run=dry_run,
    )
    return result.returncode == 0


def clone_dataset(src: str, dest: str, *, log_file: str | None = None) -> None:
    run(["zfs", "clone", src, dest], log_file=log_file)


def destroy_dataset(name: str, *, log_file: str | None = None) -> None:
    run(["zfs", "destroy", "-r", name], log_file=log_file)


def get_mountpoint(name: str, *, log_file: str | None = None) -> str:
    result = run(["zfs", "get", "-H", "-o", "value", "mountpoint", name], log_file=log_file)
    return result.stdout.strip()
