import aiofiles from pathlib import Path from lightsync.models.show import ShowModel class ShowStore: def __init__(self, shows_dir: Path): self._dir = shows_dir def ensure_dir(self) -> None: self._dir.mkdir(parents=True, exist_ok=True) def _path_for(self, show_id: str) -> Path: return self._dir / f"{show_id}.json" async def save(self, show: ShowModel) -> None: path = self._path_for(str(show.id)) async with aiofiles.open(path, "w") as f: await f.write(show.model_dump_json(indent=2)) async def load(self, show_id: str) -> ShowModel | None: path = self._path_for(show_id) if not path.exists(): return None async with aiofiles.open(path) as f: return ShowModel.model_validate_json(await f.read()) def list_ids(self) -> list[str]: return [p.stem for p in self._dir.glob("*.json")]