from helix.calculators.subarray_helper import extract_subarray
from helix.constants.seismic_anchor_validation_error import SeismicAnchorValidationError


class SeismicAnchorValidator(object):
    def __init__(self, calculator):
        self.calculator = calculator

    def validate(self, panel_data):
        subarray_summary = self.calculator.subarray_summary()
        for subarray in subarray_summary:
            subarray_panels = extract_subarray(panel_data, subarray.subarray_number)
            seismic_anchor_count = sum(panel.seismic_anchors or 0 for panel in subarray_panels)
            if subarray.required_seismic_anchors > seismic_anchor_count:
                return SeismicAnchorValidationError.TooFewAnchors
