#include "server_config.h"
#include <iostream>

namespace scar {

ServerConfig::ServerConfig()
    : db_path_(DEFAULT_DB_PATH),
      cert_path_(DEFAULT_CERT_PATH),
      key_path_(DEFAULT_KEY_PATH),
      host_(DEFAULT_HOST),
      port_(DEFAULT_PORT),
      jwt_secret_(DEFAULT_JWT_SECRET) {}

void ServerConfig::load(const std::string& config_file) {
    JsonConfig config(config_file);
    
    if (config.load()) {
        std::cout << "Loaded configuration from " << config_file << std::endl;
        
        db_path_ = config.get<std::string>("database", DEFAULT_DB_PATH);
        cert_path_ = config.get<std::string>("ssl_certificate", DEFAULT_CERT_PATH);
        key_path_ = config.get<std::string>("ssl_key", DEFAULT_KEY_PATH);
        host_ = config.get<std::string>("host", DEFAULT_HOST);
        port_ = config.get<uint16_t>("port", DEFAULT_PORT);
        jwt_secret_ = config.get<std::string>("jwt_secret", DEFAULT_JWT_SECRET);
    } else {
        std::cout << "Config file not found, using defaults" << std::endl;
    }
    
    // Warn if using default JWT secret
    if (jwt_secret_ == DEFAULT_JWT_SECRET) {
        std::cerr << "WARNING: Using default JWT secret! Change this in production!" << std::endl;
    }
}

} // namespace scar
