import json
from typing import List

from production.box import ViewBox


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:
            name = getattr(view_box.view, 'printer', None)
            if name and name not in info:
                info.append(name)

        return json.dumps(info)
