/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2022,  Regents of the University of California,
 *                           Arizona Board of Regents,
 *                           Colorado State University,
 *                           University Pierre & Marie Curie, Sorbonne University,
 *                           Washington University in St. Louis,
 *                           Beijing Institute of Technology,
 *                           The University of Memphis.
 *
 * This file is part of NFD (Named Data Networking Forwarding Daemon).
 * See AUTHORS.md for complete list of NFD authors and contributors.
 *
 * NFD 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.
 *
 * NFD 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
 * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "program.hpp"
#include "core/version.hpp"

#include <iostream>
#include <unistd.h>

#include <boost/exception/diagnostic_information.hpp>

namespace ndn::autoconfig_server {

static void
usage(const char* programName)
{
  std::cout << "Usage: " << programName << " [-h] [-V] [-p prefix]... <hub-face>\n"
            << "\n"
            << "Options:\n"
            << "  -h        - print usage and exit\n"
            << "  -V        - print version number and exit\n"
            << "  -p prefix - a local prefix of the hub\n"
            << "  hub-face  - a FaceUri to reach the hub\n";
}

static int
main(int argc, char** argv)
{
  Options options;

  int opt = -1;
  while ((opt = ::getopt(argc, argv, "hVp:")) != -1) {
    switch (opt) {
    case 'h':
      usage(argv[0]);
      return 0;
    case 'V':
      std::cout << NFD_VERSION_BUILD_STRING << std::endl;
      return 0;
    case 'p':
      options.routablePrefixes.emplace_back(::optarg);
      break;
    default:
      usage(argv[0]);
      return 2;
    }
  }

  if (argc != ::optind + 1) {
    usage(argv[0]);
    return 2;
  }

  if (!options.hubFaceUri.parse(argv[::optind])) {
    std::cerr << "ERROR: cannot parse hub FaceUri" << std::endl;
    return 2;
  }

  try {
    Face face;
    KeyChain keyChain;
    Program program(options, face, keyChain);
    program.run();
  }
  catch (const std::exception& e) {
    std::cerr << "ERROR: " << boost::diagnostic_information(e);
    return 1;
  }
  return 0;
}

} // namespace ndn::autoconfig_server

int
main(int argc, char** argv)
{
  return ndn::autoconfig_server::main(argc, argv);
}
