/* KMBuilderConfigJson.h
 *
 * Copyright (C) 2023 OpenKylin, Inc
 */

#ifndef __BUILDER_CONFIG_JSON_H__
#define __BUILDER_CONFIG_JSON_H__

#include "KMBuilderConfig.h"

const string getString(const Json::Value &node, const string &key);
const bool getBool(const Json::Value &node, const string &key);
const vector<string> getStringArray(const Json::Value &node, const string &key);
void prasejsonNode(Json::Value sourcesNode, shared_ptr<KMBuilderModule> &builderModule, string configPath, std::string savedDemarshalBaseDir);

class KMBuilderConfigJson : public KMBuilderConfig
{
public:
    KMBuilderConfigJson();
    ~KMBuilderConfigJson();

    bool loadConfigFile(const string &configFile) final;

    any getAttribute(const string &name) final;

    void setConfigPath(const string &configPath);
    shared_ptr<KMBuilderModule> getSharedModule(const string &path);

private:
    bool loadBase();
    shared_ptr<KMBuildOptions> getBuildOptions(const Json::Value &node);
    void loadAddExtensions();
    void loadAddBuildExtensions();
    const shared_ptr<BuilderExtension> getExtension(const Json::Value &node);
    const vector<shared_ptr<KMBuilderModule>> getNodeModules(const Json::Value &node);

    shared_ptr<KMBuilderModule> parseModuleNode(string filepath, const Json::Value &node);

private:
    Json::Value m_rootNode;
};

#endif // !__BUILDER_FLOW_H__
