#include "server.h"
#include "version.h"
#include <iostream>

std::shared_ptr<spdlog::logger> g_Logger = nullptr;
int main(int argc, char* argv[])
{
    g_Logger = get_logger("server", "server.log");
    g_Logger->info("Build At {} {} under {} on {}", __DATE__, __TIME__, VERSION_GIT_COMMIT,
                   VERSION_GIT_BRANCH);
    int port = 9898;
    if (argc < 2) {
        g_Logger->info("Use Default Port:{}", port);
    } else {
        std::string str_port(argv[1]);
        port = std::stoi(str_port);
        g_Logger->info("Use Port:{}", port);
    }
    asio::io_context io_context;
    CTcpServer server(io_context, g_Logger);
    if (!server.start(port)) {
        return -1;
    }
    io_context.run();
    return 0;
}