// Copyright 2020 Google LLC
//
// Licensed 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
//
//     https://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.

package com.google.graphgeckos.dashboard.storage;

/**
 * An interface for providing unified I/O to the storage component.
 */
public interface DataRepository {
  /**
   * Creates a new database entry, with just the metadata of a commit.
   *
   * @param entryData a JSON in plain string format, must have a "commitHash" field.
   * @throws IllegalArgumentException if entryData is null or doesn't have a
   *      "commitHash" field.
   */
  void createNewEntry(final ParsedGitData entryData);

  /**
   * Updates an existing database entry, with the individual information from
   * a particular buildbot.
   *
   * @param updateData a JSON in plain string format, must have a "commitHash" field.
   * @throws IllegalArgumentException if entryData is null or doesn't have a
   *     "commitHash" field.
   */
  void updateExistingEntry(final ParsedBuildbotData updateData);

  /**
   * Deletes a database entry which has its commit hash equal to the one provided in the
   * arguments.
   *
   * @param commitHash the String representation of the commit hash of the revision data to
   * be deleted.
   */
  void deleteEntryByCommitHash(final String commitHash);

  /**
   * Queries the database for a specified amout of entries, going down in chronological
   * order, starting from an offest.
   *
   * @param number is the number of database entries to retrieve.
   * @param offset is the offset from the latest database entry, for which to consider
   *     the requested number of entries.
   * @return an iterable object containing at most {@code number} entries starting
   *     from the latest entry - {@code offset}. If the database has not enough entries
   *     for the requested {@code offset} and {@code number}, returns all the available
   *     entries from that range.
   * @throws IllegalArgumentException if either number or offset are < 0.
   */
  Iterable<AggregatedBuildbotData> getLastEntries(final int number, final int offset)
                                                         throws IllegalArgumentException {
}

@@ -819,16 +819,98 @@
  commit.
+ If there already%0A   * is an entry with the same commit hash, ignores the request.
 %0A   *%0A  
@@ -935,35 +935,30 @@
 a a 
-JSON in pla
+ParsedGitData 
 in
- 
 st
-ring format
+ance
 , mu
@@ -959,32 +959,41 @@
 ce, must have a 
+non-null 
 %22commitHash%22 fie
@@ -1126,11 +1126,8 @@
 eate
-New
 Entr
@@ -1272,16 +1272,105 @@
 uildbot.
+ If there is no entry associated with the provided commit hash,%0A   * ignores the request.
 %0A   *%0A  
@@ -1396,35 +1396,35 @@
 a a 
-JSON in pla
+ParsedBuildbotData 
 in
- 
 st
-ring format
+ance
 , mu
@@ -1433,16 +1433,25 @@
  have a 
+non-null 
 %22commitH
@@ -1592,16 +1592,8 @@
 ateE
-xistingE
 ntry
@@ -1856,16 +1856,83 @@
 deleted.
+ Has no effect if there is no Entity associated to the commit hash.
 %0A   */%0A 
@@ -1952,20 +1952,8 @@
 ntry
-ByCommitHash
 (fin
@@ -2028,16 +2028,17 @@
 ied amou
+n
 t of ent
@@ -2855,13 +2855,12 @@
 xception
- %7B
+;
 %0A%7D%0A

update documentation