import json
from pathlib import Path

from planemapper.constants import CONFIG_PATH as _CONFIG_PATH

# Module-level reference so tests can monkeypatch this name
CONFIG_PATH: Path = _CONFIG_PATH


def read() -> dict:
    with CONFIG_PATH.open() as f:
        return json.load(f)


def write(data: dict) -> None:
    CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
    with CONFIG_PATH.open("w") as f:
        json.dump(data, f, indent=2)


def wipe() -> None:
    CONFIG_PATH.unlink(missing_ok=True)
