package io.delphi.qa.auto.awsmfrw.managers.helpers.db;

import io.delphi.qa.auto.awsmfrw.managers.helpers.db.bigTable.BigTableClient;
import io.delphi.qa.auto.awsmfrw.managers.helpers.db.pg.HlPostgres;
import io.delphi.qa.auto.awsmfrw.managers.helpers.db.snowflake.MgSnowflake;
import io.qameta.allure.Step;

import java.util.Map;

public class MgDb {

  private HlPostgres pg;
  private SnowflakeClient snowflakeClient;
  private MgSnowflake mgSnowflake;
  private BigTableClient bt;

  public HlPostgres postgres(Map<String, String> secretMap) {
    // TODO by alexeyisakov @4/22/21#2:29 PM: Implement case when two different connections
    // required.
    return pg == null ? pg = new HlPostgres(secretMap) : pg;
  }

  public SnowflakeClient snowflake(final Map<String, String> secretMap) {
    return snowflakeClient == null
        ? (snowflakeClient = new SnowflakeClient(secretMap))
        : snowflakeClient.getConnectionRole().equals(secretMap.get("role"))
            ? snowflakeClient
            : (snowflakeClient = new SnowflakeClient(secretMap));
  }

  @Step("Use snowflake.delphidev")
  public MgSnowflake sf() {
    return mgSnowflake == null ? mgSnowflake = new MgSnowflake() : mgSnowflake;
  }

  public BigTableClient bigTable(Map<String, String> secretMap) {
    return bt == null ? bt = new BigTableClient(secretMap) : bt;
  }
}
