#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
VERSION_FILE="$ROOT_DIR/version.json"

new_version="$(python3 - "$VERSION_FILE" <<'PY'
import json, sys, pathlib
path = pathlib.Path(sys.argv[1])
data = json.loads(path.read_text())
current = data.get("marketing_version")
if not current:
    raise SystemExit("marketing_version missing in version.json")
parts = current.split(".")
if len(parts) != 3 or not all(part.isdigit() for part in parts):
    raise SystemExit(f"Invalid marketing_version format: {current}")
parts[-1] = str(int(parts[-1]) + 1)
data["marketing_version"] = ".".join(parts)
path.write_text(json.dumps(data, indent=2) + "\n")
print(data["marketing_version"])
PY
)"

echo "$new_version"
