"""Clone target-path derivation.

Extracted from ``mgf.vm.operations.clone`` (Wave 1). Pure path algebra —
no filesystem access — so it lives in core. The actual disk copy /
overlay creation stays in the adapter (qemu-img / shutil).
"""

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from pathlib import Path


def derive_clone_path(source: Path, new_name: str, *, index: int) -> Path:
    """Pick a sibling filename under the source's directory.

    Primary disk (``index=0``): ``<parent>/<new_name><suffix>``.
    Additional disks: ``<parent>/<new_name>-<index><suffix>``.
    The suffix is taken from the source so a raw source produces a raw
    clone, a qcow2 source produces a qcow2 clone, etc.
    """
    suffix = source.suffix or ".qcow2"
    stem = new_name if index == 0 else f"{new_name}-{index}"
    return source.parent / f"{stem}{suffix}"


__all__ = ["derive_clone_path"]
