"""Incrementa la versione (semver) nel file VERSION. Default: patch +1.
Uso:  uv run python scripts/bump_version.py [major|minor|patch]   (default patch)
Stampa la nuova versione. Usato da scripts/deploy.sh ad ogni deploy."""
import sys
from pathlib import Path

VF = Path(__file__).resolve().parents[1] / "VERSION"


def main():
    part = sys.argv[1] if len(sys.argv) > 1 else "patch"
    cur = VF.read_text().strip() if VF.exists() else "0.0.0"
    try:
        major, minor, patch = (int(x) for x in cur.split("."))
    except Exception:
        major, minor, patch = 0, 0, 0
    if part == "major":
        major, minor, patch = major + 1, 0, 0
    elif part == "minor":
        minor, patch = minor + 1, 0
    else:
        patch += 1
    new = f"{major}.{minor}.{patch}"
    VF.write_text(new + "\n")
    print(new)


if __name__ == "__main__":
    main()
