# Path: clouddq/classes/metadata_registry_defaults.py
# class MetadataRegistryDefaults:
#     """ """
# 
#     default_configs: dict
# 
#     @classmethod
#     def from_dict(
#         cls: MetadataRegistryDefaults, kwargs: dict
#     ) -> MetadataRegistryDefaults:
#         default_configs = {}
#         logger.debug(f"Parsing input 'metadata_registry_defaults':\n {pformat(kwargs)}")
#         for registry_scheme, registry_defaults in kwargs.items():
#             scheme = EntityUriScheme.from_scheme(registry_scheme)
#             default_configs[scheme.value] = {}
#             expected_uri_fields = None
#             if scheme == EntityUriScheme.DATAPLEX:
#                 expected_uri_fields = DATAPLEX_URI_FIELDS
#             else:
#                 raise NotImplementedError(
#                     f"'metadata_registry_default' not implemented for registry '{scheme}' "
#                 )
#             for key, value in registry_defaults.items():
#                 if key not in expected_uri_fields:
#                     raise ValueError(
#                         f"'metadata_registry_default' for scheme '{scheme}' "
#                         f"contains unexpected field '{key}'."
#                     )
#                 default_configs[scheme][key] = value
#         return MetadataRegistryDefaults(default_configs=default_configs)
# 
#     def to_dict(self: MetadataRegistryDefaults) -> dict:
#         return self.default_configs
# 
#     def get_dataplex_registry_defaults(self, key: str | None = None) -> str | None:
#         if self.default_configs.get("DATAPLEX", None):
#             if key:
#                 return self.default_configs["DATAPLEX"].get(key, None)
#             else:
#                 return self.default_configs["DATAPLEX"]
#         else:
#             return None
# 
# Path: clouddq/lib.py
# def load_metadata_registry_default_configs(
#     configs_path: Path,
# ) -> MetadataRegistryDefaults:
#     configs = load_configs(configs_path, DqConfigType.METADATA_REGISTRY_DEFAULTS)
#     try:
#         return MetadataRegistryDefaults.from_dict(configs)
#     except ValueError as e:
#         logger.warning(e)
#         return MetadataRegistryDefaults.from_dict({})


from pathlib import Path
from clouddq.classes.metadata_registry_defaults import MetadataRegistryDefaults
from clouddq.lib import load_metadata_registry_default_configs
import logging
import os
import shutil
import pytest
import yaml

    def test_load_configs_identical(self, source_configs_path, dataplex_expected_defaults, tmp_path):
        # Load a config directory containing two copies of the same config
        try:
            temp_dir = Path(tmp_path).joinpath("clouddq_test_metadata_registry_defaults_1")
            config_path = Path(source_configs_path)

            temp_dir.mkdir(parents=True)

            assert os.path.isfile(config_path / 'metadata_registry_defaults.yml')
            shutil.copy(config_path / 'metadata_registry_defaults.yml', temp_dir / 'metadata_registry_defaults1.yml')
            shutil.copy(config_path / 'metadata_registry_defaults.yml', temp_dir / 'metadata_registry_defaults2.yml')

            loaded_config = load_metadata_registry_default_configs(temp_dir)

            assert loaded_config.to_dict() == dataplex_expected_defaults
        finally:
            shutil.rmtree(temp_dir)

    def test_load_configs_different(self, source_configs_path, dataplex_expected_defaults, tmp_path):
        # Load a config directory containing two different configs defining the same key
        try:
            temp_dir = Path(tmp_path).joinpath("clouddq_test_metadata_registry_defaults_2")
            config_path = Path(source_configs_path)

            temp_dir.mkdir(parents=True)

            assert os.path.isfile(config_path / 'metadata_registry_defaults.yml')
            shutil.copy(config_path / 'metadata_registry_defaults.yml', temp_dir / 'metadata_registry_defaults1.yml')


# Path: clouddq/classes/metadata_registry_defaults.py
# class MetadataRegistryDefaults:
#     """ """
# 
#     default_configs: dict
# 
#     @classmethod
#     def from_dict(
#         cls: MetadataRegistryDefaults, kwargs: dict
#     ) -> MetadataRegistryDefaults:
#         default_configs = {}
#         logger.debug(f"Parsing input 'metadata_registry_defaults':\n {pformat(kwargs)}")
#         for registry_scheme, registry_defaults in kwargs.items():
#             scheme = EntityUriScheme.from_scheme(registry_scheme)
#             default_configs[scheme.value] = {}
#             expected_uri_fields = None
#             if scheme == EntityUriScheme.DATAPLEX:
#                 expected_uri_fields = DATAPLEX_URI_FIELDS
#             else:
#                 raise NotImplementedError(
#                     f"'metadata_registry_default' not implemented for registry '{scheme}' "
#                 )
#             for key, value in registry_defaults.items():
#                 if key not in expected_uri_fields:
#                     raise ValueError(
#                         f"'metadata_registry_default' for scheme '{scheme}' "
#                         f"contains unexpected field '{key}'."
#                     )
#                 default_configs[scheme][key] = value
#         return MetadataRegistryDefaults(default_configs=default_configs)
# 
#     def to_dict(self: MetadataRegistryDefaults) -> dict:
#         return self.default_configs
# 
#     def get_dataplex_registry_defaults(self, key: str | None = None) -> str | None:
#         if self.default_configs.get("DATAPLEX", None):
#             if key:
#                 return self.default_configs["DATAPLEX"].get(key, None)
#             else:
#                 return self.default_configs["DATAPLEX"]
#         else:
#             return None
# 
# Path: clouddq/lib.py
# def load_metadata_registry_default_configs(
#     configs_path: Path,
# ) -> MetadataRegistryDefaults:
#     configs = load_configs(configs_path, DqConfigType.METADATA_REGISTRY_DEFAULTS)
#     try:
#         return MetadataRegistryDefaults.from_dict(configs)
#     except ValueError as e:
#         logger.warning(e)
#         return MetadataRegistryDefaults.from_dict({})


# Path: tests/unit/test_metadata_registry_defaults.py
from pathlib import Path
from clouddq.classes.metadata_registry_defaults import MetadataRegistryDefaults
from clouddq.lib import load_metadata_registry_default_configs
import logging
import os
import shutil
import pytest
import yaml


    def test_load_configs_identical(self, source_configs_path, dataplex_expected_defaults, tmp_path):
        # Load a config directory containing two copies of the same config
        try:
            temp_dir = Path(tmp_path).joinpath("clouddq_test_metadata_registry_defaults_1")
            config_path = Path(source_configs_path)

            temp_dir.mkdir(parents=True)

            assert os.path.isfile(config_path / 'metadata_registry_defaults.yml')
            shutil.copy(config_path / 'metadata_registry_defaults.yml', temp_dir / 'metadata_registry_defaults1.yml')
            shutil.copy(config_path / 'metadata_registry_defaults.yml', temp_dir / 'metadata_registry_defaults2.yml')

            loaded_config = load_metadata_registry_default_configs(temp_dir)

            assert loaded_config.to_dict() == dataplex_expected_defaults
        finally:
            shutil.rmtree(temp_dir)

    def test_load_configs_different(self, source_configs_path, dataplex_expected_defaults, tmp_path):
        # Load a config directory containing two different configs defining the same key
        try:
            temp_dir = Path(tmp_path).joinpath("clouddq_test_metadata_registry_defaults_2")
            config_path = Path(source_configs_path)

            temp_dir.mkdir(parents=True)

            assert os.path.isfile(config_path / 'metadata_registry_defaults.yml')
            shutil.copy(config_path / 'metadata_registry_defaults.yml', temp_dir / 'metadata_registry_defaults1.yml')


            loaded_config = load_metadata_registry_default_configs(temp_dir)