from pos_model import Order

from comp_exceptions import MaxSaleItemsQtyException


class FiscalOrderValidationService(object):

    def __init__(
        self,                          # type: FiscalOrderValidationService
        max_items_to_fiscalization,    # type: int
    ):
        # type: (...) -> None

        self.max_items_to_fiscalization = max_items_to_fiscalization

    def validate_qty_sale_items(
        self,     # type: FiscalOrderValidationService
        order,    # type: Order
    ):
        # type: (...) -> None

        line_quantities = sum([sale_item.quantity for sale_item in order.sale_items])
        if line_quantities > self.max_items_to_fiscalization:
            raise MaxSaleItemsQtyException(qty=self.max_items_to_fiscalization)
