"""Allowlisted database adapters for external data sources."""

from pathlib import Path

from app.core.data_source.adapters.mysql import MySQLAdapter
from app.core.data_source.adapters.postgresql import PostgreSQLAdapter
from app.core.data_source.errors import DataSourceTypeUnsupported


def adapter_for(database_type: str, certificate_dir=None):
    normalized = str(database_type or "").strip().lower()
    options = {}
    if certificate_dir is not None:
        options["certificate_dir"] = Path(certificate_dir)
    if normalized in {"postgresql", "postgres"}:
        return PostgreSQLAdapter(**options)
    if normalized == "mysql":
        return MySQLAdapter(**options)
    raise DataSourceTypeUnsupported()


__all__ = ["adapter_for", "PostgreSQLAdapter", "MySQLAdapter"]
