/*
 * LampFactory.cpp
 *
 *  Created on: December 28, 2019
 *      Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
 */

#include <output/items/Lamp.h>
#include "LampFactory.h"
#include "output/items/detail/Lamp.h"

namespace flippR_driver
{
namespace output
{

LampFactory::LampFactory(nlohmann::json &object, std::shared_ptr<DriverBoardPinController> pin_controller) :
  Factory{object, pin_controller}
{}

std::map<std::string, std::shared_ptr<items::Item>> LampFactory::getItemMap()
{
  auto lamps = this->object.at("lamps");
  std::map<std::string, std::shared_ptr<items::Item>> lamp_map;
  for (auto lamp : lamps)
  {
    auto name = lamp.at("name").get<std::string>();
    auto address = lamp.at("address").get<uint8_t >();
    auto extender = lamp.at("extender").get<std::string>();
    auto pin_base = this->get_extender_pin_base(extender);
    auto lamp_item = std::make_shared<items::detail::Lamp>(std::static_pointer_cast<DriverBoardPinController>(this->pin_controller), address, pin_base, name);
    lamp_map.emplace(name, lamp_item);
  }
  return lamp_map;
}

}
}
