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

#include <output/DriverBoardPinController.h>
#include <output/items/detail/Flipper.h>
#include "FlipperFactory.h"

namespace flippR_driver
{
namespace output
{

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

std::map<std::string, std::shared_ptr<items::Flipper>> FlipperFactory::getItemMap()
{
  auto flippers = this->object.at(config_path::flipper_path);
  std::map<std::string, std::shared_ptr<items::Flipper>> flipper_map;
  for (auto flipper : flippers)
  {
    auto name = flipper.at(config_path::item_name).get<std::string>();
    auto address = flipper.at(config_path::item_address).get<uint8_t >();

    auto flipper_item = std::make_shared<items::detail::Flipper>(std::static_pointer_cast<DriverBoardPinController>(this->pin_controller), address, name);
    flipper_map.emplace(name, flipper_item);
  }
  return flipper_map;
}

}
}
