#pragma once

#include <webserv/config/GlobalConfig.hpp>
#include <webserv/config/ServerConfig.hpp> // for ServerConfig

#include <memory> // for unique_ptr
#include <string> // for string
#include <vector> // for vector

class ADirective;
class GlobalConfig;

class ConfigManager
{
  public:
    ConfigManager &operator=(const ConfigManager &other) = delete;
    ConfigManager &&operator=(const ConfigManager &&other) = delete;
    ConfigManager(const ConfigManager &other) = delete;
    ConfigManager(const ConfigManager &&other) = delete;

    void init(const std::string &filePath);
    static ConfigManager &getInstance();

    [[nodiscard]] std::vector<ServerConfig *> getServerConfigs() const;
    [[nodiscard]] ServerConfig *getMatchingServerConfig(const std::string &host, int port) const;
    [[nodiscard]] ServerConfig *getMatchingServerConfig(const std::string &host_port) const;
    [[nodiscard]] GlobalConfig *getGlobalConfig() const;

  private:
    bool initialized_;
    ConfigManager();
    ~ConfigManager();
    std::unique_ptr<GlobalConfig> globalConfig_;

    void parseConfigFile(const std::string &filePath);
};