import pandas as pd

from typing import Union
from PyQt5.QtWidgets import QWidget

from src.utils.base.base import BaseMediator, BaseDirectoryMonitor, BaseDataConverter, BasePlotWidget, BasePointPassportFormer


class Mediator(BaseMediator):

    def notify(self,
               source: Union[BaseDirectoryMonitor, BaseDataConverter, BasePointPassportFormer, BasePlotWidget],
               data: Union[list[str], list[pd.DataFrame], list[list], list[QWidget]]):
        if issubclass(source.__class__, BaseDirectoryMonitor):
            self._converter.convert_data(data)

        if issubclass(source.__class__, BaseDataConverter):
            self._passportFormer.form_passports(data)

        if issubclass(source.__class__, BasePointPassportFormer):
            self._plot.build(data)

        if issubclass(source.__class__, BasePlotWidget):
            self._controller.send_widgets(data)
        
    def push_settings(self, settings: list[dict]):
        self._monitor.update_settings(settings)
        self._passportFormer.update_settings(settings)
        self._monitor.force_all_dir()


