/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2018-2023, Regents of the University of California.
 *
 * This file is part of NDN repo-ng (Next generation of NDN repository).
 * See AUTHORS.md for complete list of repo-ng authors and contributors.
 *
 * repo-ng is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "config.hpp"
#include "extended-error-message.hpp"
#include "repo.hpp"

#include <iostream>
#include <string.h> // for strsignal()

#include <boost/asio/io_context.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/program_options.hpp>

#include <ndn-cxx/util/logger.hpp>

NDN_LOG_INIT(repo.main);

int
main(int argc, char** argv)
{
  std::string configFile(DEFAULT_CONFIG_FILE);

  namespace po = boost::program_options;
  po::options_description optsDesc("Options");
  optsDesc.add_options()
    ("help,h",        "print this help message and exit")
    ("config-file,c", po::value<std::string>(&configFile)->default_value(configFile),
                      "path to configuration file")
    ;

  po::variables_map vm;
  try {
    po::store(po::parse_command_line(argc, argv, optsDesc), vm);
    po::notify(vm);
  }
  catch (const po::error& e) {
    std::cerr << "ERROR: " << e.what() << std::endl;
    return 2;
  }
  catch (const boost::bad_any_cast& e) {
    std::cerr << "ERROR: " << e.what() << std::endl;
    return 2;
  }

  if (vm.count("help") != 0) {
    std::cout << "Usage: " << argv[0] << " [options]\n"
              << "\n"
              << optsDesc;
    return 0;
  }

  boost::asio::io_context ioCtx;

  /// \todo reload config file on SIGHUP
  boost::asio::signal_set signalSet(ioCtx, SIGINT, SIGTERM);
  signalSet.async_wait([&ioCtx] (const boost::system::error_code& error, int signalNo) {
    if (!error) {
      NDN_LOG_FATAL("Exiting on signal " << signalNo << "/" << strsignal(signalNo));
      ioCtx.stop();
    }
  });

  try {
    repo::Repo repo(ioCtx, repo::parseConfig(configFile));
    repo.initializeStorage();
    repo.enableValidation();
    repo.enableListening();

    ioCtx.run();
  }
  catch (const std::exception& e) {
    NDN_LOG_FATAL(repo::getExtendedErrorMessage(e));
    return 1;
  }

  return 0;
}
