"""
Punto de entrada de validación para import de una fila BOM.
"""
from typing import Dict, Any, Optional, Set, List

from .common import (
    validate_row_required_parent,
    validate_row_required_component,
    validate_row_quantity,
    validate_row_lengths,
    validate_row_optional_numbers,
    validate_row_fks,
)


def validate_row_bom(
    row: Dict[str, Any],
    line_num: int,
    valid_part_numbers: Optional[Set[str]] = None,
) -> List[Dict[str, Any]]:
    """
    Valida una fila de CSV de BOMs.
    Encadena: requeridos (padre, componente, cantidad) → longitudes → opcionales numéricos → FKs.
    """
    errors: List[Dict[str, Any]] = []

    for err in [
        validate_row_required_parent(row, line_num),
        validate_row_required_component(row, line_num),
        validate_row_quantity(row, line_num),
        validate_row_lengths(row, line_num),
        validate_row_optional_numbers(row, line_num),
        validate_row_fks(row, line_num, valid_part_numbers),
    ]:
        if err:
            errors.append(err)

    return errors
