// 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 immutable container used for providing stripped-down build bot information
 * to the StorageController. Provides functionality for checking whether the information
 * is sufficient for an update of an entry. Does not modify or validity check the individual
 * contents of each field.
 *
 * Fields included: 
 * -commitHash: the commit hash of the revision built by a certain build bot.
 * -builderName: the name of the build bot which performed the compilation.
 * -logs: name of the stage and links to the logs for each stage of the compilation.
 * -status: the final result of the compilation (passed or failed).
 */
public class ParsedBuildbotData {
  private final String commitHash;
  private final String builderName;
  private final List<String> logs;
  private final boolean status;

  /**
   * Constructs an immutable instance of a ParsedBuildbotData.
   *
   * @param commitHash the commit hash of the revision this data refers to.
   * @param builderName the name of the builder which performed the compilation.
   * @param logs logs for each individual stage of compilation.
   * @param status the results of the compilation (True for passed, False for failed).
   */
  public ParsedBuildbotData(String commitHash, String builderName,
                            List<String> logs, boolean status) {
    this.commitHash = commitHash;
    this.builderName = builderName;
    this.logs = new LinkedList<>(logs);
    this.status = status;
  }

  /**
   * Checks for the existance of the fields necessary for updating a database entry.
   * Does not check the validity of each field.
   *
   * @return True if all required fields are available, False if not.
   */
  boolean validUpdateData() {
    return (commitHash != null && builderName != null && logs != null);
  }

  /**
   * Getter for the commitHash.
   *
   * @return the commitHash.
   */
  String getCommitHash() {
    return commitHash;
  }

  /**
   * Getter for the builderName.
   *
   * @return the builderName.
   */
  String getBuilderName() {
    return builderName;
  }

  /**
   * Getter for the logs.
   *
   * @return the logs.
   */
  List<String> getLogs() {
    return logs;
  }

  /**
   * Getter for the status.
   *
   * @return the status.
   */
  boolean getStatus() {
    return status;
  }
}

@@ -1384,29 +1384,26 @@
  final List%3C
-Strin
+Lo
 g%3E logs;%0A  p
@@ -1580,17 +1580,16 @@
 efers to
-.
 %0A   * @p
@@ -1652,33 +1652,32 @@
  the compilation
-.
 %0A   * @param log
@@ -1724,16 +1724,88 @@
 ilation.
+ See %7B@link%0A   *      #com.google.graphgeckos.dashboard.storage.Log Log%7D
 %0A   * @p
@@ -1882,17 +1882,16 @@
  failed)
-.
 %0A   */%0A 
@@ -1989,21 +1989,18 @@
    List%3C
-Strin
+Lo
 g%3E logs,
@@ -2482,24 +2482,324 @@
 null);%0A  %7D%0A%0A
+  /**%0A   * Converts this instance to an instance of %7B@link com.gogle.graphgeckos.dashboard.storage.Builder%0A   * Builder%7D.%0A   *%0A   * @return a new Builder instance, with the fields copied from the calling instance.%0A   */%0A  Builder toBuilder() %7B%0A    return new Builder(builderName, logs, status);%0A  %7D%0A%0A
   /**%0A   * G
@@ -3129,21 +3129,18 @@
 %0A  List%3C
-Strin
+Lo
 g%3E getLo

integrate Builder and Log classes to parsedBuildbotData