#ifndef DEVICE_HOLDER_H
#define DEVICE_HOLDER_H
#include "barrier/barrier_properties.h"
#include "barrier/barrier.h"
#include "platform_scale/platform_scale.h"
#include "platform_scale/platform_scale_properties.h"
#include "sound_column/sound_column.h"
#include "sound_column/sound_column_properties.h"
#include "vidicon/vidicon.h"
#include "vidicon/vidicon_properties.h"

namespace zsy {

    struct DeviceConfig
    {
        std::vector<BarrierProperties> barriers;
        std::vector<PlatformScaleProperties> platformScales;
        std::vector<SoundColumnProperties> soundColumns;
        std::vector<VidiconProperties> vidicons;
    };

    inline void from_json(const nlohmann::json &j, DeviceConfig &o)
    {
        PARSE_JSON(barriers, o.barriers);
        PARSE_JSON(platformScales, o.platformScales);
        PARSE_JSON(soundColumns, o.soundColumns);
        PARSE_JSON(vidicons, o.vidicons);
    }


    class DeviceHolder
    {
        std::unordered_map<std::string, std::shared_ptr<Barrier> > barriers;
        std::unordered_map<std::string, std::shared_ptr<PlatformScale> > platformScales;
        std::unordered_map<std::string, std::shared_ptr<SoundColumn> > soundColumns;
        std::unordered_map<std::string, std::shared_ptr<Vidicon> > vidicons;

        std::unordered_map<std::string, std::unordered_map<std::string, std::string> > relation;

        void initBarriers(std::vector<BarrierProperties> &configs);

        void initPlatformScales(std::vector<PlatformScaleProperties> &configs);

        void initSoundColumns(std::vector<SoundColumnProperties> &configs);

        void initVidicons(std::vector<VidiconProperties> &configs);

    public:
        DeviceHolder(const nlohmann::json &config);

        std::shared_ptr<Barrier> getBarrier(const std::string &barrier_sn);

        std::shared_ptr<PlatformScale> getPlatformScale(const std::string &barrier_sn);

        std::shared_ptr<SoundColumn> getSoundColumn(const std::string &barrier_sn);

        std::shared_ptr<Vidicon> getVidicon(const std::string &barrier_sn);
    };

} // zsy

#endif //DEVICE_HOLDER_H
