from pathlib import Path

from gallery.sketch.source import ApiSource


class MockSource(ApiSource):

    def __init__(self, path: Path, mapping: dict[str, str]):
        super().__init__("")
        self._path = path
        self._mapping = mapping

    async def request(self, endpoint: str) -> str:
        for pattern, filename in self._mapping.items():
            if pattern in endpoint:
                return (self._path / filename).read_text()
        raise ValueError(endpoint)
