/**
* Nudsf_DataRepository
* Nudsf Data Repository Service. © 2021, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved. 
*
* The version of the OpenAPI document: 1.1.0-alpha.2
* 
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "udsf_server.hpp"
#include "logger.hpp"
#include "options.hpp"
#include "udsf_config.hpp"
#include "HttpReq.hpp"

#include <string>
#include <ctime>
//#include "pch.h"
#include "Connection.h"
#include "ConnectionPool.h"

using namespace config;
udsf_config udsf_cfg;

int main(int argc, char **argv) {
    if (!Options::parse(argc, argv)) {
        std::cout << "Options::parse() failed" << std::endl;
        return 1;
    }

    Logger::init("UDSF", Options::getlogStdout(), Options::getlogRotFilelog());
    Logger::udsf_app().startup("Options parsed!");
    if(udsf_cfg.load(Options::getlibconfigConfig()) < 0) return 0;
         udsf_cfg.display();

    Logger::udsf_app().debug("Initiating UDSF server endpoints");
    Pistache::Address addr(udsf_cfg.sbi.addr4, Pistache::Port(udsf_cfg.sbi.port));

    ConnectionPool* p = ConnectionPool::getConnectionPool();
    //clock_t begin = clock();
    

    // MYSQL mysql;
    // mysql_init(&mysql);
    // if (!mysql_real_connect(&mysql, udsf_cfg.mysql.mysql_server.c_str(),
    //                       udsf_cfg.mysql.mysql_user.c_str(),
    //                       udsf_cfg.mysql.mysql_pass.c_str(),
    //                       udsf_cfg.mysql.mysql_db.c_str(), udsf_cfg.mysql.mysql_port, 0, CLIENT_MULTI_STATEMENTS)) {
    //     Logger::udsf_app().error("An error occurred while connecting to db: %s",
    //     mysql_error(&mysql));
    //     return 0;
    // }
    // UDSFApiServer udsfApiServer(addr, &mysql);
    // udsfApiServer.init(PISTACHE_SERVER_THREADS);
    // std::thread udsf_api_manager(&UDSFApiServer::start, udsfApiServer);
    UDSFApiServer udsfApiServer(addr);
    udsfApiServer.init(PISTACHE_SERVER_THREADS);
    std::thread udsf_api_manager(&UDSFApiServer::start, udsfApiServer);




    pause();
    //mysql_close(&mysql);
    return 0;
}

