package com.google.sps.tool;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import java.util.List;
import java.util.ArrayList;
import com.google.sps.data.Card;
import com.google.sps.data.Folder;

public class EntityTestingTool {

  public static boolean checkForNoNullValues(Entity card) {
    return (card.getProperty("blobKey") != null  &&
      card.getProperty("labels") != null &&
      card.getProperty("textTranslated") != null &&
      card.getProperty("textNotTranslated") != null &&
      card.getProperty("fromLang") != null &&
      card.getProperty("toLang") != null &&
      card.getProperty("cardKey") != null);
  }

  public static List<Folder> populateDatastoreWithFolders(Folder folderA, Folder folderB, DatastoreService datastore, String userKey) {
    
    Entity folderEntityA = folderA.createEntity(KeyFactory.stringToKey(userKey));
    Entity folderEntityB = folderB.createEntity(KeyFactory.stringToKey(userKey));

    // Update entity in datastore 
    datastore.put(folderEntityA);
    datastore.put(folderEntityB);

    List<Folder> folders = new ArrayList<>();
    folders.add(new Folder(folderEntityA));
    folders.add(new Folder(folderEntityB));

    return folders;
  }

  public static List<Card> populateDatastoreWithCards(Card cardA, Card cardB, DatastoreService datastore, String folderKey) {
    
    Entity cardEntityA = cardA.createEntity(KeyFactory.stringToKey(folderKey));
    Entity cardEntityB = cardB.createEntity(KeyFactory.stringToKey(folderKey));

    // Update entity in datastore 
    datastore.put(cardEntityA);
    datastore.put(cardEntityB);

    List<Card> cards = new ArrayList<>();
    cards.add(new Card(cardEntityA));
    cards.add(new Card(cardEntityB));

    return cards;
  }

    
}
@@ -874,28 +874,22 @@
  static 
-List%3C
 Folder
-%3E
  populat
@@ -906,15 +906,15 @@
 With
+A
 Folder
-s
 (Fol
@@ -927,25 +927,8 @@
 lder
-A, Folder folderB
 , Da
@@ -999,17 +999,16 @@
 erEntity
-A
  = folde
@@ -1012,91 +1012,8 @@
 lder
-A.createEntity(KeyFactory.stringToKey(userKey));%0A    Entity folderEntityB = folderB
 .cre
@@ -1126,51 +1126,16 @@
 tity
-A);%0A    datastore.put(folderEntityB
 );%0A%0A    
 List
@@ -1134,66 +1134,30 @@
     
-List%3C
 Folder
-%3E
  folder
-s = new ArrayList%3C%3E();%0A    folders.add(
+Object = 
 new 
@@ -1171,26 +1171,24 @@
 folderEntity
-A)
 );%0A    folde
@@ -1192,67 +1192,117 @@
 lder
-s.add(new Folder(folderEntityB));%0A%0A    return folders;%0A  %7D%0A
+Object.setFolderKey(KeyFactory.keyToString(folderEntity.getKey()));%0A    %0A    return folderObject;%0A  %7D%0A  %0A  /*
 %0A  p
@@ -1826,20 +1826,25 @@
 n cards;%0A  %7D
+%0A  */
 %0A%0A    %0A%7D

Add a helper function that populateDatastore with a single folder only