import json
from typing import List

from production.box import ViewBox
from production.view import PrinterView


class GetPrintersInfoInteractor(object):
    def __init__(self, view_boxes):
        # type: (List[ViewBox]) -> None
        self.view_boxes = view_boxes

    def execute(self):
        # type: () -> str
        info = []
        for view_box in self.view_boxes:
            view = view_box.view
            if not isinstance(view, PrinterView):
                continue

            printer_name = view.get_printer_name()
            if printer_name is None:
                continue

            if printer_name not in info:
                info.append(printer_name)

        return json.dumps(info)
