package tv.pluto;

import io.qameta.allure.Description;
import io.qameta.allure.TmsLink;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
import tv.pluto.core.BaseTest;
import tv.pluto.grpc.config.ConfigClient;
import tv.pluto.ip.dal.config.Config;

public class ConfigTestSuite extends BaseTest {
  private ConfigClient configClient;

  private static final String REPOSITORY = "main-preprod.t58qw.mongodb.net/pluto-main";
  private static final String REPOSITORY_PREPRD = "main-preprod-pl-0.t58qw.mongodb.net/pluto-main";

  @BeforeClass(alwaysRun = true)
  private void setUp() {
    configClient = new ConfigClient(grpcChannelManager.getChannel());
  }

  @Test
  @Description("Get config for the DAL - GetConfigInfo")
  @TmsLink("28500730")
  public void C28500730_TEST() {
    Config.GetConfigInfoResponse config = configClient.getConfigInfo();

    SoftAssert softAssert = new SoftAssert();
    softAssert.assertEquals(config.getVersion(), SERVICE_VERSION);

    if (!config.getEnvironment().equals("preprd") && !config.getEnvironment().equals("preprod"))
      /* Preprod and preprd databases are the same */
      //            softAssert.assertEquals(config.getEnvironment(),
      // MongoUtils.getENVIRONMENT().toLowerCase());

      if (config.getEnvironment().equals("preprd")) {
        softAssert.assertEquals(config.getRepositories().getMongodb(), REPOSITORY_PREPRD);
        softAssert.assertEquals(config.getService(), "service-dal");
      } else {
        softAssert.assertTrue(
            config.getRepositories().getMongodb().endsWith("mongodb.net/pluto-main"));
        softAssert.assertEquals(config.getService(), SERVICE_NAME);
      }

    softAssert.assertAll();
  }
}
