from dataclasses import dataclass
import ipaddress
from .common_val_functions import validate_enum_constraint
import pandas as pd


class FabricValidator:
    def __init__(self, fabric_schema: dict):
        self.fabric_schema = fabric_schema

    def validate_fabrics(self, df: pd.DataFrame):
        """Validate toponodes section by processing constraints"""
        if df is None or df.empty:
            return []

        errors = []
        validation_rules = self.fabric_schema.get("validation_rules", {})
        config = validation_rules.get("config", {})

        # Define constraint handlers
        constraint_handlers = {
            "enum_validation": validate_enum_constraint,
        }

        # Process non-grouping constraints
        constraints = validation_rules.get("constraints", [])
        for constraint in constraints:
            constraint_type = constraint.get("type")
            handler = constraint_handlers.get(constraint_type)
            if handler:
                errors.extend(
                    handler(df=df, constraint=constraint, config=config) or []
                )

        return errors
