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 java.util.Map;
import java.util.HashMap;
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("rawText") != null &&
      card.getProperty("fromLang") != null &&
      card.getProperty("toLang") != null &&
      card.getProperty("cardKey") != null);
  }

  public static Folder populateDatastoreWithAFolder(Folder folder, DatastoreService datastore, String userKey) {
    
    Entity folderEntity = folder.createEntity(KeyFactory.stringToKey(userKey));

    // Update entity in datastore 
    datastore.put(folderEntity);

    Folder folderObject = new Folder(folderEntity);
    folderObject.setFolderKey(KeyFactory.keyToString(folderEntity.getKey()));
    
    return folderObject;
  }
  
  /*
  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;
  }
  */

  public static Map<String, Object> getExpectedJsonFolderInfo(List<Folder> folders, boolean showCreateFormStatus) {

    Map<String, Object> expectedJsonInfo = new HashMap<>();
    expectedJsonInfo.put("showCreateFormStatus", showCreateFormStatus);
    expectedJsonInfo.put("userFolders", folders);

    return expectedJsonInfo;
  }

  public static Map<String, Object> getExpectedJsonCardInfo(List<Card> cards, boolean showCreateFormStatus) {

    Map<String, Object> expectedJsonInfo = new HashMap<>();
    expectedJsonInfo.put("showCreateFormStatus", showCreateFormStatus);
    expectedJsonInfo.put("userCards", cards);

    return expectedJsonInfo;
  }
}
@@ -842,53 +842,8 @@
 ) !=
- null &&%0A      card.getProperty(%22cardKey%22) !=
  nul
@@ -1290,13 +1290,8 @@
 %0A  %0A
-  /*%0A
   pu
@@ -1302,26 +1302,20 @@
  static 
-List%3C
 Card
-%3E
  populat
@@ -1328,21 +1328,21 @@
 toreWith
+A
 Card
-s
 (Card ca
@@ -1347,21 +1347,8 @@
 card
-A, Card cardB
 , Da
@@ -1423,97 +1423,15 @@
 tity
-A
  = card
-A.createEntity(KeyFactory.stringToKey(folderKey));%0A    Entity cardEntityB = cardB
 .cre
@@ -1544,49 +1544,16 @@
 tity
-A);%0A    datastore.put(cardEntityB
 );%0A%0A    
 List
@@ -1552,60 +1552,26 @@
     
-List%3C
 Card
-%3E
  card
-s = new ArrayList%3C%3E();%0A    cards.add(
+Object = 
 new 
@@ -1589,10 +1589,8 @@
 tity
-A)
 );%0A 
@@ -1600,22 +1600,48 @@
 card
-s.add(new Card
+Object.setCardKey(KeyFactory.keyToString
 (car
@@ -1651,9 +1651,17 @@
 tity
-B
+.getKey()
 ));%0A
@@ -1680,19 +1680,19 @@
 card
-s;%0A  %7D%0A  */
+Object;%0A  %7D
 %0A%0A  

Simplify populateDatastore[...] function to produce only 1 card