#include "service_runner.hpp"
#include "utils/hash.hpp"
#include "utils/directories.hpp"
#include "utils/utils.hpp"
#include "templates.hpp"

#include <fstream>
#include <filesystem>
#include <unistd.h>

namespace fs = std::filesystem;

namespace dropshell {

service_versions::service_versions(const std::string & server_name, const std::string & service_name) 
    : m_server_name(server_name), m_service_name(service_name)
{
}

uint64_t service_versions::calculate_version_local_service_template()
{
    template_info tinfo;
    if (!get_template_info(m_service_name, tinfo)) {
        return 0;   
    }
    return hash_directory_recursive(tinfo.local_template_path);
}

uint64_t service_versions::calculate_version_local_config()
{
    std::string config_path = localpath::service(m_server_name, m_service_name);
    if (config_path.empty() || !fs::exists(config_path)) {
        return 0;
    }
    return hash_directory_recursive(config_path);
}

void service_versions::update_stored_remote_versions()
{
    uint64_t template_hash = calculate_version_remote_service_template();
    uint64_t config_hash = calculate_version_remote_config();

    // TODO - actually update things!
}

uint64_t service_versions::get_version_remote_config()
{
    // TODO - actually get the version!
    return 0;
}

uint64_t service_versions::get_version_remote_service_template()
{
    // TODO - actually get the version!
    return 0;
}

uint64_t service_versions::calculate_version_remote_service_template()
{
    // TODO - actually get the version!
    return 0;
}

uint64_t service_versions::calculate_version_remote_config()
{   
    // TODO - actually get the version!
    return 0;
}

} // namespace dropshell 