'use strict';

// //////////////////////////////////////////////////////////////////////////////
// DISCLAIMER
//
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
//
// The Programs (which include both the software and documentation) contain
// proprietary information of ArangoDB GmbH; they are provided under a license
// agreement containing restrictions on use and disclosure and are also
// protected by copyright, patent and other intellectual and industrial
// property laws. Reverse engineering, disassembly or decompilation of the
// Programs, except to the extent required to obtain interoperability with
// other independently created software or as specified by law, is prohibited.
//
// It shall be the licensee's responsibility to take all appropriate fail-safe,
// backup, redundancy, and other measures to ensure the safe use of
// applications if the Programs are used for purposes such as nuclear,
// aviation, mass transit, medical, or other inherently dangerous applications,
// and ArangoDB GmbH disclaims liability for any damages caused by such use of
// the Programs.
//
// This software is the confidential and proprietary information of ArangoDB
// GmbH. You shall not disclose such confidential and proprietary information
// and shall use it only in accordance with the terms of the license agreement
// you entered into with ArangoDB GmbH.
//
// @author Heiko Kernbach
// //////////////////////////////////////////////////////////////////////////////

const internal = require('internal');
const arangosh = require('@arangodb/arangosh');
const generalGraphClient = require('@arangodb/general-graph');

const db = internal.db;


const GRAPH_PREFIX = '_api/gharial/';

exports._graph = generalGraphClient._graph;

exports._create = function (name, edgeDefinitions, orphans) {
  const data = {
    options: {
      replicationFactor: "satellite"
    }
  };
  if (name) {
    data.name = name;
  }
  if (edgeDefinitions) {
    data.edgeDefinitions = edgeDefinitions;
  }
  if (orphans) {
    data.orphanCollections = orphans;
  }

  const uri = GRAPH_PREFIX;
  const requestResult = arangosh.checkRequestResult(db._connection.POST(uri, JSON.stringify(data)));
  db._flushCache();
  // should always be a SatelliteGraph
  return generalGraphClient.__graphToClass(requestResult.graph);
};

exports._drop = generalGraphClient._drop;
exports._list = generalGraphClient._drop;
exports._listObjects = generalGraphClient._drop;
exports._exists = generalGraphClient._exists;
exports._relation = generalGraphClient._relation;
exports._edgeDefinitions = generalGraphClient._edgeDefinitions;
exports._extendEdgeDefinitions = generalGraphClient._extendEdgeDefinitions;
