from __future__ import annotations
import json
from pathlib import Path

class ConfigManager:
    def __init__(self, path: str = "nest_ui.config.json"):
        self.path = Path(path)
        self.data = {}

    def load(self):
        if self.path.exists():
            self.data = json.loads(self.path.read_text(encoding="utf-8"))
        return self.data

    def save(self):
        self.path.write_text(json.dumps(self.data, indent=2, ensure_ascii=False), encoding="utf-8")
        return str(self.path)

    def set(self, key, value):
        self.data[key] = value

    def get(self, key, default=None):
        return self.data.get(key, default)
