from typing import List


class StackedPlotConfig:
    def __init__(self, config_list: List):
        pass


class StackedPlotConfigList:
    def __init__(self):
        self.list: List[StackedPlotConfig] = []

    def get_stacked_plot_config_from_assay(
        self, assay_name: str
    ) -> List[StackedPlotConfig]:
        """
        Return StackedPlotConfig related to an assay or a column.
        """
        result = []
        for config in self.list:
            assay_def = config.assay_def
            columns = assay_def.columns.keys()
            if assay_name in columns or assay_name == assay_def.variable:
                result.append(config)

        return result

    def remove_config(self, config: StackedPlotConfig):
        """
        Remove configuration from list
        If plot is associated to configuration, plot is also deleted

        Args:
            config: (StackedPlotConfig) configuration
        """

        if config.plot is not None:
            # Update visibility even if plot is deleted later
            # so we can count number of visible plot if main thread as not process event
            config.plot.setVisible(False)
            config.plot.deleteLater()
        self.list.remove(config)
