// 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.datatypes;

import com.google.cloud.Timestamp;
import java.util.ArrayList;
import java.util.List;
import org.springframework.cloud.gcp.data.datastore.core.mapping.Entity;
import org.springframework.cloud.gcp.data.datastore.core.mapping.Field;
import org.springframework.data.annotation.Transient;
import org.springframework.lang.NonNull;

/**
 * Contains the information retrieved from a single build bot. It is used as a member
 * of {@link BuildInfo}
 */
@Entity(name = "builder")
public class BuildBotData {

  /**
   * The commit hash, it is fetched from the BuildBot API.
   * This field is transient because it is only needed to
   * determine which commit this data belongs to and put
   * it in the right {@link BuildInfo} in the storage.
   * Used in {@link com.google.graphgeckos.dashboard.storage.DatastoreRepository}.
   */
  @Transient
  @Field(name = "commitHash")
  private String commitHash;

  /** 
   * The timestamp of the build. 
   */
  @Field(name = "timestamp")
  private Timestamp timestamp;

  /**
   * Name of the buildbot.
   */
  @Field(name = "name")
  private String name;

  /**
   * The logs of each compilation stage, stored as described by {@link Log}.
   */
  @Field(name = "logs")
  private final List<Log> logs = new ArrayList<>();

  /**
   * Builder compilation status, as described by {@link BuilderStatus}.
   */
  @Field(name = "status")
  private BuilderStatus status;

  /**
   * Only used by Spring GCP.
   */
  public BuildBotData() { }

  public BuildBotData(String commitHash, String name, List<Log> logs, BuilderStatus status) {
    this.commitHash = commitHash;
    this.name = name;
    this.logs.addAll(logs);
    this.status = status;
  }

  /**
   * Returns the name of the builder bot. Cannot be null.
   */
  public String getName() {
    return name;
  }

  /**
   * Returns the list of logs for each compilation stage. Cannot be null.
   */
  public List<Log> getLogs() {
    return logs;
  }

  /**
   * Returns the compilation status of the builder. Cannot be null.
   */
  public BuilderStatus getStatus() {
    return status;
  }

  /**
   * Returns the commit hash of the commit tested by the current buildbot.
   */
  public String getCommitHash() {
    return commitHash;
  }

  /**
   * Returns the timestamp of the build.
   */
  public Timestamp getTimestamp() {
    return timestamp;
  }

  /**
   * Sets the name of the builder bot.
   *
   * @param name the new value for the {@code name} field. Should not be null.
   */
  public void setName(@NonNull String name) {
    this.name = name;
  }

  /**
   * Sets the list of logs for each compilation stage.
   *
   * @param logs the new value for the {@code logs} field. Should not be null.
   */
  public void setLogs(@NonNull List<Log> logs) {
    this.logs = new ArrayList<>(logs);
  }

  /**
   * Sets the compilation status of the builder.
   *
   * @param status the new value for the {@code status} field. Should not be null.
   */
  public void setStatus(@NonNull BuilderStatus status) {
    this.status = status;
  }

  /**
   * Sets the commit hash of the commit tested by the current buildbot.
   *
   * @param commitHash the new value for the {@code commitHash} field. Should not be null.
   */
  public void setCommitHash(@NonNull String commitHash) {
    this.commitHash = commitHash;
  }

  /**
   * Sets the timestamp of the build.
   *
   * @param timestamp the new value for the {@code timestamp} field. Should not be null.
   */
  public void setTimestamp(@NonNull Timestamp timestamp) {
    this.timestamp = timestamp;
  }

}

@@ -2323,31 +2323,31 @@
 %0A  /**%0A   * 
-R
+@r
 eturn
-s
  the name of
@@ -2358,20 +2358,16 @@
  builder
- bot
 . Cannot
@@ -2374,32 +2374,43 @@
  be null.%0A   */%0A
+  @NonNull%0A
   public String 
@@ -2450,31 +2450,31 @@
 %0A  /**%0A   * 
-R
+@r
 eturn
-s
  the list of
@@ -2521,32 +2521,43 @@
  be null.%0A   */%0A
+  @NonNull%0A
   public List%3CLo
@@ -2596,39 +2596,39 @@
   %7D%0A%0A  /**%0A   * 
-R
+@r
 eturn
-s
  the compilation
@@ -2665,32 +2665,43 @@
  be null.%0A   */%0A
+  @NonNull%0A
   public Builder
@@ -2752,31 +2752,31 @@
 %0A  /**%0A   * 
-R
+@r
 eturn
-s
  the commit 
@@ -2825,22 +2825,49 @@
 uildbot.
-%0A   */
+ Cannot be null.%0A   */%0A  @NonNull
 %0A  publi
@@ -2936,15 +2936,15 @@
   * 
-R
+@r
 eturn
-s
  the
@@ -2966,32 +2966,43 @@
 he build.%0A   */%0A
+  @NonNull%0A
   public Timesta
@@ -3058,52 +3058,8 @@
 /**%0A
-   * Sets the name of the builder bot.%0A   *%0A
    *
@@ -3222,68 +3222,8 @@
 /**%0A
-   * Sets the list of logs for each compilation stage.%0A   *%0A
    *
@@ -3406,62 +3406,8 @@
 /**%0A
-   * Sets the compilation status of the builder.%0A   *%0A
    *
@@ -3589,85 +3589,8 @@
 /**%0A
-   * Sets the commit hash of the commit tested by the current buildbot.%0A   *%0A
    *
@@ -3789,51 +3789,8 @@
 /**%0A
-   * Sets the timestamp of the build.%0A   *%0A
    *

update documentation