"""
Carga de conjuntos FK para validación de import CSV de BOMs.
"""
from typing import Set

from core.database import CoreSessionLocal


def load_boms_fk_sets(tenant_id: int, company_id: int) -> Set[str]:
    """Carga valid_part_numbers (Part.part_number por tenant/company)."""
    valid_part_numbers: Set[str] = set()
    try:
        with CoreSessionLocal() as session:
            from api.v1.modules.a76.parts.models import Part
            for p in (
                session.query(Part.part_number)
                .filter(
                    Part.tenant_id == tenant_id,
                    Part.company_id == company_id,
                )
                .all()
            ):
                valid_part_numbers.add(p[0])
    except Exception as e:
        import logging
        logging.getLogger(__name__).warning("BOMs import: could not load parts: %s", e)
    return valid_part_numbers
