from typing import Callable, Dict, Generic, Optional, TypeVar

from ._ProviderBuilder import ProviderBuilder

T = TypeVar("T")


class ConfigProviderBuilder(Generic[T], ProviderBuilder):
    def __init__(self, transform_method: Optional[Callable[[Dict], T]] = None) -> None:
        super().__init__()
        self.transform_method = transform_method

    def build_config(self) -> T:
        config_provider = self.build_provider()
        configuration_data = config_provider.get_configuration()
        if self.transform_method is None:
            return configuration_data  # type: ignore
        return self.transform_method(configuration_data)
