content: package ru.dimension.ui.component.module.preview;
  
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Map.Entry;
  import java.util.Optional;
  import lombok.Data;
  import lombok.extern.log4j.Log4j2;
  import ru.dimension.db.core.DStore;
  import ru.dimension.db.model.profile.CProfile;
  import ru.dimension.ui.component.module.PreviewChartModule;
  import ru.dimension.ui.manager.ProfileManager;
  import ru.dimension.ui.model.ProfileTaskQueryKey;
  import ru.dimension.ui.model.info.QueryInfo;
  import ru.dimension.ui.model.info.TableInfo;
  import ru.dimension.ui.model.info.gui.ChartInfo;
  import ru.dimension.ui.state.SqlQueryState;
  
  @Data
  @Log4j2
  public class PreviewModel {
    private final ProfileTaskQueryKey key;
    private final QueryInfo queryInfo;
    private final ChartInfo chartInfo;
    private final TableInfo tableInfo;
    private final ProfileManager profileManager;
    private final SqlQueryState sqlQueryState;
    private final DStore dStore;
  
    private final Map<CProfile, PreviewChartModule> chartModules = new HashMap<>();
  
    public PreviewModel(ProfileTaskQueryKey key,
                        QueryInfo queryInfo,
                        ChartInfo chartInfo,
                        TableInfo tableInfo,
                        ProfileManager profileManager,
                        SqlQueryState sqlQueryState,
                        DStore dStore) {
      this.key = key;
      this.queryInfo = queryInfo;
      this.chartInfo = chartInfo.copy();
      this.tableInfo = tableInfo;
      this.profileManager = profileManager;
      this.sqlQueryState = sqlQueryState;
      this.dStore = dStore;
    }
  
    public void addChartModule(CProfile cProfile, PreviewChartModule module) {
      chartModules.put(cProfile, module);
    }
  
    public void clearChartModules() {
      chartModules.clear();
    }
  
    public Optional<Entry<CProfile, PreviewChartModule>> getChartModuleByColumnName(String columnName) {
      return chartModules.entrySet().stream()
          .filter(module -> module.getKey().getColName().equals(columnName))
          .findFirst();
    }
  
    public void removeChartModule(CProfile cProfile) {
      chartModules.remove(cProfile);
    }
  }