


#include "kubecontrol/PodController.hpp"
#include "nlohmann/json_fwd.hpp"
#include <memory>
#include <string>
#include <thread>
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include "loguru.hpp"


SCENARIO("Testing KubePod")
{


  // kubecontrol::PodController podc("docs/config");

  kubecontrol::KubernetesAPI api(YAML::LoadFile("docs/config"));
  std::string name = "componenttest1";


  std::string uuid = name;
  std::string controller = "controller";
  std::string type = "ship";
  std::string image = "ship:latest";
  kubecontrol::KubePod ShipPod1("controller",uuid,type,image,"simulator");
  ShipPod1.setName(name);

  nlohmann::json vars;
  vars["ENTITY_ID"] = uuid;
  vars["ENTITY_NAME"] = "FGS Hamburg";
  vars["ENTITY_SIDE"] = "Neutral";
  vars["POSITION"]["LAT"] = "55";
  vars["POSITION"]["LON"] = "8";
  vars["POSITION"]["Height"] = "0";
  vars["COURSE"] = "0";
  vars["SPEED"] = "0";
  vars["GROUNDTRUTH_PORT"] = std::to_string(10000);
  vars["GROUNDTRUTH_ADDR"] = "239.0.0.1";
  vars["COMMAND_PORT"] = "5555";
  vars["ENTITY_RCS"] = std::to_string(850);

  vars["ENTITY_SENSORS"].push_back("radar:latest");
  ShipPod1.setEnvironmentVar("CONFIG", vars.dump());


LOG_S(INFO)<<"Starting";

ShipPod1.start(api);
LOG_S(INFO)<<"started";

std::string name2 = "componenttest2";
 std::string controller2 = "controller";
  std::string type2 = "ship";
  std::string image2 = "ship:latest";
  kubecontrol::KubePod ShipPod2(controller2,name2,type2,image2,"simulator");

nlohmann::json vars1;
  vars1["ENTITY_ID"] = name2;
  vars1["ENTITY_NAME"] = "FGS Hamburg";
  vars1["ENTITY_SIDE"] = "Neutral";
  vars1["POSITION"]["LAT"] = "55";
  vars1["POSITION"]["LON"] = "8";
  vars1["POSITION"]["Height"] = "0";
  vars1["COURSE"] = "0";
  vars1["SPEED"] = "0";
  vars1["GROUNDTRUTH_PORT"] = std::to_string(10000);
  vars1["GROUNDTRUTH_ADDR"] = "239.0.0.1";
  vars1["COMMAND_PORT"] = "5555";
  vars1["ENTITY_RCS"] = std::to_string(850);

  vars["ENTITY_SENSORS"].push_back("radar:latest");
  ShipPod2.setEnvironmentVar("CONFIG", vars1.dump());

auto envmaps2 = std::map<std::string, std::string>();
envmaps2.emplace("CONFIG", vars1.dump());

  ShipPod2.addContainer("CMS", "systemprototype:latest",envmaps2);

  ShipPod2.setEnvironmentVar("CONFIG", vars.dump());
LOG_S(INFO)<<"Starting multi container pod";

ShipPod2.start(api);
LOG_S(INFO)<<"started multi container pod";




  GIVEN("different Attributes for a Track in different forms")
  {
    WHEN("constructing Track Object with data")
    {

      THEN("check if Track attributes are correct")
      {
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
        REQUIRE(ShipPod1.getUUID() == name);
        REQUIRE(ShipPod1.getName() == name);

        REQUIRE(ShipPod1.getComponent() == "ship");
        REQUIRE(ShipPod1.getOwner() == "controller");
        REQUIRE(ShipPod1.getStatus() == "Running");
        REQUIRE(!ShipPod1.getIp().empty());
        REQUIRE(ShipPod1.getPodsChilds(api).size() == 3);

        // REQUIRE(info1 != "");


          ShipPod1.stop(api);

          ShipPod2.stop(api);



      } //THEN
    } // WHEN
  } // GIVEN
} //SCENARIO
