/** @file

  A brief file description

  @section license License

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */

#include "Stats.h"

using namespace EsiLib;

namespace EsiLib
{
namespace Stats
{
  const char *STAT_NAMES[Stats::MAX_STAT_ENUM] = {"esi.n_os_docs",          "esi.n_cache_docs",   "esi.n_parse_errs",
                                                  "esi.n_includes",         "esi.n_include_errs", "esi.n_spcl_includes",
                                                  "esi.n_spcl_include_errs"};

  int g_stat_indices[Stats::MAX_STAT_ENUM] = {0};
  StatSystem *g_system                     = nullptr;

  void
  init(StatSystem *system)
  {
    g_system = system;
    if (g_system) {
      for (int i = 0; i < Stats::MAX_STAT_ENUM; ++i) {
        // FIXME doesn't return avalue.
        g_system->create(i);
        /*      if (!g_system->create(i)) {
                Utils::ERROR_LOG("[%s] Unable to create stat [%s]", __FUNCTION__, Stats::STAT_NAMES[i]);
              }*/
      }
    }
  }

  // FIXME step should be TSMgmtInt but for some reason the linker is having some strange int vs long name mangling issue.
  void
  increment(Stats::STAT st, int step /* = 1 */)
  {
    if (g_system) {
      // FIXME doesn't return avalue.
      g_system->increment(st, step);
      /*
          if (!g_system->increment(st, step)) {
            Utils::ERROR_LOG("[%s] Unable to increment stat [%s] by step [%d]", __FUNCTION__, step,
                             Stats::STAT_NAMES[st]);
          }
      */
    }
  }
}
}
