#ifndef MDD_PROCESSORBASE_H
#define MDD_PROCESSORBASE_H

#include <list>
#include "Input.h"
#include "Output.h"
#include "IProcessor.h"

namespace mdd {
    class ProcessorBase : public IProcessor{
    private:

        template<class T>
        class HandlerModule {
        public:
            std::shared_ptr<IModule> moduleHandler;
            std::shared_ptr<T> accessHandler;
            HandlerModule(std::shared_ptr<IModule> module, std::shared_ptr<T> access) {
                moduleHandler = module;
                accessHandler = access;
            }
        };

        std::string _prefix = "";
        std::string _type = "";
        int _appendix = 0;

        std::vector<std::shared_ptr<Input>> _processor_inputs;
        std::vector<std::shared_ptr<Output>> _processor_outputs;

        std::vector<HandlerModule<IInput>> _module_inputs;
        std::vector<HandlerModule<IOutput>> _module_outputs;
        std::vector<std::shared_ptr<IModule>> _modules;

    protected:
        int addProcesorInput(const std::string& type, const std::vector<double>& value);
        int addProcessorOutput(const std::string& type, const std::vector<double>& initial);
        std::shared_ptr<IOutput> getProcessorOutput(int handle);
        std::shared_ptr<IInput> getProcessorInput(int handle);
        std::shared_ptr<IModule> getModule(int handle);

    public:
        std::string getID() override ;
        std::string setType(const std::string& type) override;
        std::string getType() override;
        std::string setPrefix(const std::string& prefix) override;
        std::string setAppendix(int appendix) override;
        void updateID() override ;

        std::string addModule(std::shared_ptr<IModule> module) override ;
        void removeModule(std::shared_ptr<IModule> module) override;
        std::string addModuleInput(std::string module_ID, std::string input_ID) override;
        std::string addModuleInput(std::shared_ptr<IModule> module, std::shared_ptr<IInput> input) override;
        std::string addModuleOutput(std::string module_ID, std::string output_ID) override;
        std::string addModuleOutput(std::shared_ptr<IModule> module, std::shared_ptr<IOutput> output) override;

        std::vector<std::string> getInputs() override;
        std::vector<std::string> getOutputs() override;
        std::vector<std::string> getModules() override;

        std::vector<std::string> getInputIDs() override;
        std::vector<std::string> getOutputIDs() override;
        std::vector<std::string> getModuleIDs() override;

        std::vector<state> getInputStates() override;
        std::vector<state> getOutputStates() override;

        std::vector<std::shared_ptr<IOutput>> getInputConnections() override;
        std::vector <std::vector <std::shared_ptr<IInput>>> getOutputConnections() override;

        std::vector <std::shared_ptr<IInput>> getOptimizableInputs() override;
        std::vector <std::shared_ptr<IOutput>> getOptimizableOutputs() override;

        std::shared_ptr<IOutput> getOutput(const std::string& output_id) override;
        std::shared_ptr<IInput> getInput(const std::string& input_id) override;
        std::shared_ptr<IModule> getModule(std::string module_id) override;
    };
}
#endif
