from typing import Union

from core.configuration.feature_flags_enum import FeatureFlagsEnum
from core.environment import Environment
from data.schemas.system.feature_flag_dao import featureFlagDao


class FeatureFlags:
    _flags = {
        FeatureFlagsEnum.version_endpoint.value: True,  # 15.01.2025
        FeatureFlagsEnum.technical_demo_banner.value: False,  # 18.04.2025
    }

    _overwrite_flags = []

    @staticmethod
    def overwrite_flag(key: str):
        return key in FeatureFlags._overwrite_flags

    @staticmethod
    def get_default(key: FeatureFlagsEnum) -> bool:
        return FeatureFlags._flags[key.value]

    @staticmethod
    async def has_feature(key: Union[str, FeatureFlagsEnum]) -> bool:
        key_value = key.value if isinstance(key, FeatureFlagsEnum) else key

        value = await featureFlagDao.find_by_key(key_value)
        return (
            value.value
            if value
            else FeatureFlags.get_default(FeatureFlagsEnum(key_value))
        )
