from typing import (
    Dict,
    List,
    Optional,
    Union,
)

from ._Group import Group
from ._Key import Key


class FakeReader(object):

    def __init__(
        self,
        fake_find_value: Optional[Dict[str, Union[str, List[str]]]] = None,
        fake_find_group: Optional[Dict[str, Group]] = None,
    ) -> None:

        self.fake_find_value = fake_find_value or {}
        self.fake_find_group = fake_find_group or {}

    def find_value(
        self,
        path: str,
        default: Union[List[str], str],
    ) -> Union[str, List[str]]:

        if path in self.fake_find_value:
            return self.fake_find_value[path]

        return default

    def find_values(
        self,
        path: str,
    ) -> Union[str, List[str]]:

        return self.find_value(
            path=path,
            default=[],
        )

    def find_group(
        self,
        path: str,
        keys: Optional[List[Key]] = None,
    ) -> Group:

        if path in self.fake_find_group:
            return self.fake_find_group[path]

        return Group(
            name=path,
            keys=keys,
        )
