package com.google.sps.Objects;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.Entity;
import com.google.sps.servlets.ServletHelper;

public final class Group {

  private final ArrayList<String> memberIds;
  private final ArrayList<Challenge> challenges;
  private final ArrayList<Post> posts;
  private final ArrayList<Option> options;
  private final String groupName;
  private final String headerImg;
  private final long groupId;

  public Group(
      ArrayList<String> memberIds,
      ArrayList<Challenge> challenges,
      ArrayList<Post> posts,
      ArrayList<Option> options,
      String groupName,
      String headerImg,
      long groupId) {
    this.memberIds = memberIds;
    this.challenges = challenges;
    this.posts = posts;
    this.options = options;
    this.groupName = groupName;
    this.headerImg = headerImg;
    this.groupId = groupId;
  }

  public ArrayList<String> getMemberIds() {
    return memberIds;
  }

  public ArrayList<Challenge> challenges() {
    return challenges;
  }

  public ArrayList<Post> getPosts() {
    return posts;
  }

  public ArrayList<Option> getOptions() {
    return options;
  }

  public String getGroupName() {
    return groupName;
  }

  public String getHeaderImg() {
    return headerImg;
  }

  public long getGroupId() {
    return groupId;
  }

  public void addChallenge(Challenge newChallenge) {
    this.challenges.add(newChallenge);
  }

  public void addMember(String memberId) {
    this.memberIds.add(memberId);
  }

  public void addPost(Post newPost) {
    this.posts.add(newPost);
  }

  public static Entity getGroupEntity(
      HttpServletRequest request, HttpServletResponse response, DatastoreService datastore)
      throws IOException {
    String groupIdString = request.getParameter("groupId");
    long groupId = Long.parseLong(groupIdString);
    Entity groupEntity = ServletHelper.getEntityFromId(response, groupId, datastore, "Group");
    return groupEntity;
  }
}

@@ -341,22 +341,16 @@
 %0Apublic 
-final 
 class Gr
@@ -423,33 +423,28 @@
 l ArrayList%3C
-Challe
+Lo
 ng
-e
 %3E challenges
@@ -438,24 +438,26 @@
 g%3E challenge
+Id
 s;%0A  private
@@ -473,26 +473,28 @@
 rayList%3C
-Post
+Long
 %3E post
+Id
 s;%0A  pri
@@ -514,30 +514,28 @@
 rayList%3C
-Opti
+L
 on
+g
 %3E option
 s;%0A  pri
@@ -522,24 +522,26 @@
 Long%3E option
+Id
 s;%0A  private
@@ -693,33 +693,28 @@
   ArrayList%3C
-Challe
+Lo
 ng
-e
 %3E challenges
@@ -731,20 +731,20 @@
 rayList%3C
-Post
+Long
 %3E posts,
@@ -760,22 +760,20 @@
 rayList%3C
-Opti
+L
 on
+g
 %3E option
@@ -895,16 +895,18 @@
 hallenge
+Id
 s = chal
@@ -926,16 +926,18 @@
 his.post
+Id
 s = post
@@ -954,16 +954,18 @@
 s.option
+Id
 s = opti
@@ -1156,25 +1156,20 @@
 rayList%3C
-Challe
+Lo
 ng
-e
 %3E challe
@@ -1193,24 +1193,26 @@
 rn challenge
+Id
 s;%0A  %7D%0A%0A  pu
@@ -1226,20 +1226,20 @@
 rayList%3C
-Post
+Long
 %3E getPos
@@ -1256,24 +1256,26 @@
  return post
+Id
 s;%0A  %7D%0A%0A  pu
@@ -1289,22 +1289,20 @@
 rayList%3C
-Opti
+L
 on
+g
 %3E getOpt
@@ -1323,24 +1323,26 @@
 eturn option
+Id
 s;%0A  %7D%0A%0A  pu
@@ -1538,25 +1538,20 @@
 allenge(
-Challe
+Lo
 ng
-e
  newChal
@@ -1577,16 +1577,18 @@
 hallenge
+Id
 s.add(ne
@@ -1709,20 +1709,20 @@
 addPost(
-Post
+Long
  newPost
@@ -1738,16 +1738,18 @@
 his.post
+Id
 s.add(ne
@@ -1774,15 +1774,8 @@
 lic 
-static 
 Enti

edit group file