from attr import define, Factory

from detectpii.catalog import CatalogT
from detectpii.model import PiiColumn
from detectpii.scanner import ScannerT


@define(kw_only=True)
class PiiDetectionPipeline:
    catalog: CatalogT
    scanners: list[ScannerT] = Factory(list)

    def scan(self) -> list[PiiColumn]:
        self.catalog.detect_tables()
        pii_columns = []

        for scanner in self.scanners:
            pii_columns.extend(scanner.scan(catalog=self.catalog))

        return list(set(pii_columns))
