#pragma once

#include "Input.h"
#include "Output.h"
#include "IModule.h"

namespace mdd {

    class ModuleBase : public  IModule{
    private:
        int _appendix = 0;

    protected:
        std::weak_ptr<IModule> _parent;
        json _base_config;
        ModuleBase(const std::string& base_config = "{}"); 
        const std::string type = "module";
        std::string key;
        std::vector<std::shared_ptr<Input>> inputs;
        std::vector<std::shared_ptr<Output>> outputs;

        bool configureChild(const json& config) override { return true; };

    public:
        bool configure(const json& config) override;
        const json& getConfiguration() override;

        size_t getNumInputs() override;
        size_t getNumOutputs() override;

        std::shared_ptr<IInput> getInput(size_t index) override;
        std::shared_ptr<IInput> getInput(const json& jid) override;
        std::shared_ptr<IOutput> getOutput(size_t index) override;
        std::shared_ptr<IOutput> getOutput(const json& jid) override;

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

        void setParent(std::shared_ptr<IModule> parent) override;
        std::vector<std::string> getParentID() override;
        
        std::string getGeneratorKey() override;
        std::string getType() override;
        std::string setAppendix(int appendix) override;
        int getAppendix() override;
        std::string getID() override;
    
        void load(const json& j) override;
        json dump() override;

        json getIdentifier() override;

        void disconnect() override;
    };
}