#include "attach_modulesToTestbench.h"

//#include "rlutil.h"
#include "SensorSlotOfTestbench.h"

// using namespace rlutil;

bool attach_csvReaderModuleToSensorSlotInAgent(
    Testbench *testbench, Sensor *sensor, CSVreaderModule *csvReaderModule) {
  if (testbench != NULL && sensor != NULL && csvReaderModule != NULL) {
    SensorSlotOfTestbench *sensorSlot =
        testbench->get_sensorSlotAddressOfTestbench(sensor);
    if (sensorSlot != NULL) {
      printf("   > CSV-Reader ");
      // setColor(TXTCOLOR_LIGHTCYAN);
      printf("%s ", csvReaderModule->get_name());
      // setColor(TXTCOLOR_GREY);
      printf("(id: %03u) ", csvReaderModule->get_id());
      if (sensorSlot->set_csvReaderModule(csvReaderModule)) {
        // setColor(TXTCOLOR_LIGHTGREEN);
        printf("attached ");
        // setColor(TXTCOLOR_GREY);
        printf("to Sensor ");
        // setColor(TXTCOLOR_LIGHTCYAN);
        printf("%s ", sensor->get_name());
        // setColor(TXTCOLOR_GREY);
        printf("(id: %03u) in Testbench ", sensor->get_id());
        // setColor(TXTCOLOR_LIGHTCYAN);
        printf("%s ", testbench->get_name());
        // setColor(TXTCOLOR_GREY);
        printf("(id: %03u)\n", testbench->get_id());
        return true;
      } else {
        // setColor(TXTCOLOR_LIGHTRED);
        printf("Couldn't attach the CSVreaderModule!\n");
        // setColor(TXTCOLOR_GREY);
      }
    } else {
      // setColor(TXTCOLOR_LIGHTRED);
      printf("   > Couldn't attach the CSVreaderModule because Sensor isn't "
             "registered in %s (id: %03u)!\n",
             testbench->get_name(), testbench->get_id());
      // setColor(TXTCOLOR_GREY);
    }
  } else {
    // setColor(TXTCOLOR_LIGHTRED);
    printf("   > Couldn't attach the CSVreaderModule because Testbench, "
           "Sensorm or CSVreaderModule is not valid!\n");
    // setColor(TXTCOLOR_GREY);
  }
  return false;
}
