import pandas as pd
from .normalize import norm_mac, is_mac # Usiamo norm_mac che esiste sicuramente

def load_gateway_csv(path, delimiter=";"):
    """Carica i gateway validi dal CSV."""
    try:
        df = pd.read_csv(path, sep=delimiter)
        # Normalizziamo colonne
        df.columns = [c.strip().lower() for c in df.columns]
        
        if 'mac' not in df.columns:
            return [], 0, 0
            
        valid_macs = []
        invalid_count = 0
        
        for m in df['mac'].astype(str):
            if is_mac(m):
                valid_macs.append(norm_mac(m))
            else:
                invalid_count += 1
                
        return valid_macs, invalid_count, 0
    except Exception as e:
        print(f"Errore gateways.py: {e}")
        return [], 0, 0
