/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2017, 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 "sqlite-storage.hpp"
#include "config.hpp"
#include "index.hpp"

#include <ndn-cxx/util/sha256.hpp>
#include <boost/filesystem.hpp>
#include <istream>

namespace repo {

using std::string;

SqliteStorage::SqliteStorage(const string& dbPath)
  : m_size(0)
{
  if (dbPath.empty()) {
    std::cerr << "Create db file in local location [" << dbPath << "]. " << std::endl
              << "You can assign the path using -d option" << std::endl;
    m_dbPath = string("ndn_repo.db");
  }
  else {
    boost::filesystem::path fsPath(dbPath);
    boost::filesystem::file_status fsPathStatus = boost::filesystem::status(fsPath);
    if (!boost::filesystem::is_directory(fsPathStatus)) {
      if (!boost::filesystem::create_directory(boost::filesystem::path(fsPath))) {
        BOOST_THROW_EXCEPTION(Error("Folder '" + dbPath + "' does not exists and cannot be created"));
      }
    }

    m_dbPath = dbPath + "/ndn_repo.db";
  }
  initializeRepo();
}


void
SqliteStorage::initializeRepo()
{
  char* errMsg = 0;

  int rc = sqlite3_open_v2(m_dbPath.c_str(), &m_db,
                           SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
#ifdef DISABLE_SQLITE3_FS_LOCKING
                           "unix-dotfile"
#else
                           0
#endif
                           );

  if (rc == SQLITE_OK) {
    sqlite3_exec(m_db, "CREATE TABLE NDN_REPO ("
                      "id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "
                      "name BLOB, "
                      "data BLOB, "
                      "keylocatorHash BLOB);\n "
                 , 0, 0, &errMsg);
    // Ignore errors (when database already exists, errors are expected)
  }
  else {
    std::cerr << "Database file open failure rc:" << rc << std::endl;
    BOOST_THROW_EXCEPTION(Error("Database file open failure"));
  }
  sqlite3_exec(m_db, "PRAGMA synchronous = OFF", 0, 0, &errMsg);
  sqlite3_exec(m_db, "PRAGMA journal_mode = WAL", 0, 0, &errMsg);
}

SqliteStorage::~SqliteStorage()
{
  sqlite3_close(m_db);
}

void
SqliteStorage::fullEnumerate(const std::function<void(const Storage::ItemMeta)>& f)
{
  sqlite3_stmt* m_stmt = 0;
  int rc = SQLITE_DONE;
  string sql = string("SELECT id, name, keylocatorHash FROM NDN_REPO;");
  rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &m_stmt, 0);
  if (rc != SQLITE_OK)
    BOOST_THROW_EXCEPTION(Error("Initiation Read Entries from Database Prepare error"));
  int entryNumber = 0;
  while (true) {
    rc = sqlite3_step(m_stmt);
    if (rc == SQLITE_ROW) {

      ItemMeta item;
      item.fullName.wireDecode(Block(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(m_stmt, 1)),
                                     sqlite3_column_bytes(m_stmt, 1)));
      item.id = sqlite3_column_int(m_stmt, 0);
      item.keyLocatorHash = make_shared<const ndn::Buffer>(sqlite3_column_blob(m_stmt, 3),
                                                           sqlite3_column_bytes(m_stmt, 3));

      try {
        f(item);
      }
      catch (...) {
        sqlite3_finalize(m_stmt);
        throw;
      }
      entryNumber++;
    }
    else if (rc == SQLITE_DONE) {
      sqlite3_finalize(m_stmt);
      break;
    }
    else {
      std::cerr << "Initiation Read Entries rc:" << rc << std::endl;
      sqlite3_finalize(m_stmt);
      BOOST_THROW_EXCEPTION(Error("Initiation Read Entries error"));
    }
  }
  m_size = entryNumber;
}

int64_t
SqliteStorage::insert(const Data& data)
{
  Name name = data.getName();

  Index::Entry entry(data, 0); //the id is not used
  int64_t id = -1;
  if (name.empty()) {
    std::cerr << "name is empty" << std::endl;
    return -1;
  }

  int rc = 0;

  sqlite3_stmt* insertStmt = 0;

  string insertSql = string("INSERT INTO NDN_REPO (id, name, data, keylocatorHash) "
                            "VALUES (?, ?, ?, ?)");

  if (sqlite3_prepare_v2(m_db, insertSql.c_str(), -1, &insertStmt, 0) != SQLITE_OK) {
    sqlite3_finalize(insertStmt);
    std::cerr << "insert sql not prepared" << std::endl;
  }
  //Insert
  auto result = sqlite3_bind_null(insertStmt, 1);
  if (result == SQLITE_OK) {
    result = sqlite3_bind_blob(insertStmt, 2,
                               entry.getName().wireEncode().wire(),
                               entry.getName().wireEncode().size(), SQLITE_STATIC);
  }
  if (result == SQLITE_OK) {
    result = sqlite3_bind_blob(insertStmt, 3,
                               data.wireEncode().wire(),
                               data.wireEncode().size(), SQLITE_STATIC);
  }
  if (result == SQLITE_OK) {
    BOOST_ASSERT(entry.getKeyLocatorHash()->size() == ndn::util::Sha256::DIGEST_SIZE);
    result = sqlite3_bind_blob(insertStmt, 4,
                               entry.getKeyLocatorHash()->data(),
                               entry.getKeyLocatorHash()->size(), SQLITE_STATIC);
  }

  if (result == SQLITE_OK) {
    rc = sqlite3_step(insertStmt);
    if (rc == SQLITE_CONSTRAINT) {
      std::cerr << "Insert failed" << std::endl;
      sqlite3_finalize(insertStmt);
      BOOST_THROW_EXCEPTION(Error("Insert failed"));
     }
    sqlite3_reset(insertStmt);
     m_size++;
     id = sqlite3_last_insert_rowid(m_db);
  }
  else {
    BOOST_THROW_EXCEPTION(Error("Some error with insert"));
  }

  sqlite3_finalize(insertStmt);
  return id;
}


bool
SqliteStorage::erase(const int64_t id)
{
  sqlite3_stmt* deleteStmt = 0;

  string deleteSql = string("DELETE from NDN_REPO where id = ?;");

  if (sqlite3_prepare_v2(m_db, deleteSql.c_str(), -1, &deleteStmt, 0) != SQLITE_OK) {
    sqlite3_finalize(deleteStmt);
    std::cerr << "delete statement prepared failed" << std::endl;
    BOOST_THROW_EXCEPTION(Error("delete statement prepared failed"));
  }

  if (sqlite3_bind_int64(deleteStmt, 1, id) == SQLITE_OK) {
    int rc = sqlite3_step(deleteStmt);
    if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
      std::cerr << " node delete error rc:" << rc << std::endl;
      sqlite3_finalize(deleteStmt);
      BOOST_THROW_EXCEPTION(Error(" node delete error"));
    }
    if (sqlite3_changes(m_db) != 1)
      return false;
    m_size--;
  }
  else {
    std::cerr << "delete bind error" << std::endl;
    sqlite3_finalize(deleteStmt);
    BOOST_THROW_EXCEPTION(Error("delete bind error"));
  }
  sqlite3_finalize(deleteStmt);
  return true;
}


shared_ptr<Data>
SqliteStorage::read(const int64_t id)
{
  sqlite3_stmt* queryStmt = 0;
  string sql = string("SELECT * FROM NDN_REPO WHERE id = ? ;");
  int rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &queryStmt, 0);
  if (rc == SQLITE_OK) {
    if (sqlite3_bind_int64(queryStmt, 1, id) == SQLITE_OK) {
      rc = sqlite3_step(queryStmt);
      if (rc == SQLITE_ROW) {
        auto data = make_shared<Data>();
        data->wireDecode(Block(reinterpret_cast<const uint8_t*>(sqlite3_column_blob(queryStmt, 2)),
                               sqlite3_column_bytes(queryStmt, 2)));
        sqlite3_finalize(queryStmt);
        return data;
      }
      else if (rc == SQLITE_DONE) {
        return nullptr;
      }
      else {
        std::cerr << "Database query failure rc:" << rc << std::endl;
        sqlite3_finalize(queryStmt);
        BOOST_THROW_EXCEPTION(Error("Database query failure"));
      }
    }
    else {
      std::cerr << "select bind error" << std::endl;
      sqlite3_finalize(queryStmt);
      BOOST_THROW_EXCEPTION(Error("select bind error"));
    }
    sqlite3_finalize(queryStmt);
  }
  else {
    sqlite3_finalize(queryStmt);
    std::cerr << "select statement prepared failed" << std::endl;
    BOOST_THROW_EXCEPTION(Error("select statement prepared failed"));
  }
  return nullptr;
}

int64_t
SqliteStorage::size()
{
  sqlite3_stmt* queryStmt = 0;
  string sql("SELECT count(*) FROM NDN_REPO ");
  int rc = sqlite3_prepare_v2(m_db, sql.c_str(), -1, &queryStmt, 0);
  if (rc != SQLITE_OK)
    {
      std::cerr << "Database query failure rc:" << rc << std::endl;
      sqlite3_finalize(queryStmt);
      BOOST_THROW_EXCEPTION(Error("Database query failure"));
    }

  rc = sqlite3_step(queryStmt);
  if (rc != SQLITE_ROW)
    {
      std::cerr << "Database query failure rc:" << rc << std::endl;
      sqlite3_finalize(queryStmt);
      BOOST_THROW_EXCEPTION(Error("Database query failure"));
    }

  int64_t nDatas = sqlite3_column_int64(queryStmt, 0);
  if (m_size != nDatas) {
    std::cerr << "The size of database is not correct! " << std::endl;
  }
  return nDatas;
}

} // namespace repo
