from sandwich.modeling.dataclasses import StgInfo, Dv2SystemInfo
from sandwich.modeling.metadata import modeling_metadata

from .hub_based_validator import HubBasedValidator


class Scd2DimValidator(HubBasedValidator):
    def __init__(self, profile: str):
        super().__init__(profile)
        self._on_validate_staging.append(self._validate_staging)

    @staticmethod
    def _validate_staging(stg_info: StgInfo, _: Dv2SystemInfo) -> None:

        # -----------------
        # BKs
        # -----------------
        # You don't need a hub or/and a dim tables for a non-business entity.
        # So you have to have at least one business key, and you can have more.
        # Naming convention is to just add a `bk_` prefix to the original key name
        # because we want to keep information of the original names
        if len(stg_info.bk_keys) == 0:
            raise Exception("bk column(s) are required for `hub-scd2dim` validation")


        system_column_names = stg_info.sys_columns.keys()

        if modeling_metadata.hashdiff not in system_column_names:
            raise Exception(f"{modeling_metadata.hashdiff} column is required for scd2dim validation")
        if modeling_metadata.is_available not in system_column_names:
            raise Exception(f"{modeling_metadata.is_available} column is required for scd2dim validation")
