# Path: clouddq/lib.py
# def load_configs(configs_path: Path, configs_type: DqConfigType) -> typing.Dict:
# def load_rule_bindings_config(configs_path: Path) -> typing.Dict:
# def load_rule_dimensions_config(configs_path: Path) -> list:
# def load_entities_config(configs_path: Path) -> typing.Dict:
# def load_rules_config(configs_path: Path) -> typing.Dict:
# def load_row_filters_config(configs_path: Path) -> typing.Dict:
# def load_metadata_registry_default_configs(
#     configs_path: Path,
# ) -> MetadataRegistryDefaults:
# def create_rule_binding_view_model(
#     rule_binding_id: str,
#     rule_binding_configs: typing.Dict,
#     dq_summary_table_name: str,
#     environment: str,
#     configs_cache: DqConfigsCache,
#     dq_summary_table_exists: bool = False,
#     metadata: typing.Optional[typing.Dict] = None,
#     debug: bool = False,
#     progress_watermark: bool = True,
#     default_configs: typing.Optional[typing.Dict] = None,
# ) -> str:
# def create_entity_summary_model(
#     entity_table_id: str,
#     entity_target_rule_binding_configs: dict,
#     gcp_project_id: str,
#     gcp_bq_dataset_id: str,
#     debug: bool = False,
# ) -> str:
# def write_sql_string_as_dbt_model(
#     model_id: str, sql_string: str, dbt_model_path: Path
# ) -> None:
# def prepare_configs_from_rule_binding_id(
#     rule_binding_id: str,
#     rule_binding_configs: typing.Dict,
#     dq_summary_table_name: str,
#     environment: typing.Optional[str],
#     configs_cache: DqConfigsCache,
#     dq_summary_table_exists: bool = False,
#     metadata: typing.Optional[typing.Dict] = None,
#     progress_watermark: bool = True,
#     default_configs: typing.Optional[typing.Dict] = None,
# ) -> typing.Dict:
# def prepare_configs_cache(configs_path: Path) -> DqConfigsCache:
# 
# Path: clouddq/classes/dq_config_type.py
# class DqConfigType(str, Enum):
#     """ """
# 
#     RULES = "rules"
#     RULE_BINDINGS = "rule_bindings"
#     RULE_DIMENSIONS = "rule_dimensions"
#     ROW_FILTERS = "row_filters"
#     ENTITIES = "entities"
#     METADATA_REGISTRY_DEFAULTS = "metadata_registry_defaults"
# 
#     def is_required(
#         self: DqConfigType,
#     ) -> bool:
#         if self == DqConfigType.RULES:
#             return True
#         elif self == DqConfigType.RULE_BINDINGS:
#             return True
#         elif self == DqConfigType.RULE_DIMENSIONS:
#             return False
#         elif self == DqConfigType.ROW_FILTERS:
#             return True
#         elif self == DqConfigType.ENTITIES:
#             return False
#         elif self == DqConfigType.METADATA_REGISTRY_DEFAULTS:
#             return False
#         else:
#             raise NotImplementedError(f"DQ Config Type: {self} not implemented.")
# 
#     def to_class(
#         self: DqConfigType,
#     ) -> type[DqRule] | type[DqRuleBinding] | type[DqRuleDimensions] | type[
#         DqRowFilter
#     ] | type[DqEntity] | type[MetadataRegistryDefaults]:
#         if self == DqConfigType.RULES:
#             return DqRule
#         elif self == DqConfigType.RULE_BINDINGS:
#             return DqRuleBinding
#         elif self == DqConfigType.RULE_DIMENSIONS:
#             return DqRuleDimensions
#         elif self == DqConfigType.ROW_FILTERS:
#             return DqRowFilter
#         elif self == DqConfigType.ENTITIES:
#             return DqEntity
#         elif self == DqConfigType.METADATA_REGISTRY_DEFAULTS:
#             return MetadataRegistryDefaults
#         else:
#             raise NotImplementedError(f"DQ Config Type: {self} not implemented.")


from pathlib import Path
from clouddq import lib
from clouddq.classes.dq_config_type import DqConfigType
import logging
import os
import shutil
import pytest
import yaml
        try:
            temp_dir = Path(tmp_path).joinpath("clouddq_test_lib", "test_lib_load_configs_dims")
            config_path = Path(temp_configs_dir)

            temp_dir.mkdir(parents=True)

            rule_original = config_path / 'rules' / 'base-rules.yml'

            assert os.path.isfile(rule_original)
            shutil.copy(rule_original, temp_dir / 'rule.yml')

            # TEST 1: check that it loads ok
            rules = lib.load_configs(temp_dir, DqConfigType.RULES)
            dims = lib.load_configs(temp_dir, DqConfigType.RULE_DIMENSIONS)

            assert len(rules) == 5
            assert dims == {}
            os.remove(temp_dir / 'rule.yml')

            # TEST 2: add rule_dimensions to the file and load again
            with open(rule_original) as f:
                testconfig = yaml.safe_load(f)

            dims_ref = ['COMPLETENESS', 'ACCURACY', 'CONFORMITY']
            testconfig[DqConfigType.RULE_DIMENSIONS.value] = dims_ref

            with open(temp_dir / 'rule.yml', 'w') as f:
                yaml.safe_dump(testconfig, f)

            rules = lib.load_configs(temp_dir, DqConfigType.RULES)

# Path: clouddq/lib.py
# def load_configs(configs_path: Path, configs_type: DqConfigType) -> typing.Dict:
# def load_rule_bindings_config(configs_path: Path) -> typing.Dict:
# def load_rule_dimensions_config(configs_path: Path) -> list:
# def load_entities_config(configs_path: Path) -> typing.Dict:
# def load_rules_config(configs_path: Path) -> typing.Dict:
# def load_row_filters_config(configs_path: Path) -> typing.Dict:
# def load_metadata_registry_default_configs(
#     configs_path: Path,
# ) -> MetadataRegistryDefaults:
# def create_rule_binding_view_model(
#     rule_binding_id: str,
#     rule_binding_configs: typing.Dict,
#     dq_summary_table_name: str,
#     environment: str,
#     configs_cache: DqConfigsCache,
#     dq_summary_table_exists: bool = False,
#     metadata: typing.Optional[typing.Dict] = None,
#     debug: bool = False,
#     progress_watermark: bool = True,
#     default_configs: typing.Optional[typing.Dict] = None,
# ) -> str:
# def create_entity_summary_model(
#     entity_table_id: str,
#     entity_target_rule_binding_configs: dict,
#     gcp_project_id: str,
#     gcp_bq_dataset_id: str,
#     debug: bool = False,
# ) -> str:
# def write_sql_string_as_dbt_model(
#     model_id: str, sql_string: str, dbt_model_path: Path
# ) -> None:
# def prepare_configs_from_rule_binding_id(
#     rule_binding_id: str,
#     rule_binding_configs: typing.Dict,
#     dq_summary_table_name: str,
#     environment: typing.Optional[str],
#     configs_cache: DqConfigsCache,
#     dq_summary_table_exists: bool = False,
#     metadata: typing.Optional[typing.Dict] = None,
#     progress_watermark: bool = True,
#     default_configs: typing.Optional[typing.Dict] = None,
# ) -> typing.Dict:
# def prepare_configs_cache(configs_path: Path) -> DqConfigsCache:
# 
# Path: clouddq/classes/dq_config_type.py
# class DqConfigType(str, Enum):
#     """ """
# 
#     RULES = "rules"
#     RULE_BINDINGS = "rule_bindings"
#     RULE_DIMENSIONS = "rule_dimensions"
#     ROW_FILTERS = "row_filters"
#     ENTITIES = "entities"
#     METADATA_REGISTRY_DEFAULTS = "metadata_registry_defaults"
# 
#     def is_required(
#         self: DqConfigType,
#     ) -> bool:
#         if self == DqConfigType.RULES:
#             return True
#         elif self == DqConfigType.RULE_BINDINGS:
#             return True
#         elif self == DqConfigType.RULE_DIMENSIONS:
#             return False
#         elif self == DqConfigType.ROW_FILTERS:
#             return True
#         elif self == DqConfigType.ENTITIES:
#             return False
#         elif self == DqConfigType.METADATA_REGISTRY_DEFAULTS:
#             return False
#         else:
#             raise NotImplementedError(f"DQ Config Type: {self} not implemented.")
# 
#     def to_class(
#         self: DqConfigType,
#     ) -> type[DqRule] | type[DqRuleBinding] | type[DqRuleDimensions] | type[
#         DqRowFilter
#     ] | type[DqEntity] | type[MetadataRegistryDefaults]:
#         if self == DqConfigType.RULES:
#             return DqRule
#         elif self == DqConfigType.RULE_BINDINGS:
#             return DqRuleBinding
#         elif self == DqConfigType.RULE_DIMENSIONS:
#             return DqRuleDimensions
#         elif self == DqConfigType.ROW_FILTERS:
#             return DqRowFilter
#         elif self == DqConfigType.ENTITIES:
#             return DqEntity
#         elif self == DqConfigType.METADATA_REGISTRY_DEFAULTS:
#             return MetadataRegistryDefaults
#         else:
#             raise NotImplementedError(f"DQ Config Type: {self} not implemented.")


# Path: tests/unit/test_lib.py
from pathlib import Path
from clouddq import lib
from clouddq.classes.dq_config_type import DqConfigType
import logging
import os
import shutil
import pytest
import yaml

        try:
            temp_dir = Path(tmp_path).joinpath("clouddq_test_lib", "test_lib_load_configs_dims")
            config_path = Path(temp_configs_dir)

            temp_dir.mkdir(parents=True)

            rule_original = config_path / 'rules' / 'base-rules.yml'

            assert os.path.isfile(rule_original)
            shutil.copy(rule_original, temp_dir / 'rule.yml')

            # TEST 1: check that it loads ok
            rules = lib.load_configs(temp_dir, DqConfigType.RULES)
            dims = lib.load_configs(temp_dir, DqConfigType.RULE_DIMENSIONS)

            assert len(rules) == 5
            assert dims == {}
            os.remove(temp_dir / 'rule.yml')

            # TEST 2: add rule_dimensions to the file and load again
            with open(rule_original) as f:
                testconfig = yaml.safe_load(f)

            dims_ref = ['COMPLETENESS', 'ACCURACY', 'CONFORMITY']
            testconfig[DqConfigType.RULE_DIMENSIONS.value] = dims_ref

            with open(temp_dir / 'rule.yml', 'w') as f:
                yaml.safe_dump(testconfig, f)

            rules = lib.load_configs(temp_dir, DqConfigType.RULES)

            dims = lib.load_configs(temp_dir, DqConfigType.RULE_DIMENSIONS)