package investickations.com.sfsu.controllers;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import investickations.com.sfsu.entities.Entity;

/**
 * JSONUtil class is the Utility class which provides helps to create the JSON Parser
 * for each of the entity in the application. This JSON Parser are used to retrieve the
 * data from remote connection.
 * The data representation of data retrieved are in JSOn format.
 * <p/>
 * Created by Pavitra on 5/19/2015.
 */
public class JSONUtil {
    static public class EntityJSONParser {
        ArrayList<Entity> list;

        // parse users
        static ArrayList<Entity> parseUsers(String in) throws JSONException {

            JSONObject root = new JSONObject(in);
            JSONArray personArray = root.getJSONArray("persons");

            for (int i = 0; i < personArray.length(); i++) {
                JSONObject personsJSONObject = personArray.getJSONObject(i);


            }

            return null;
        }

        // parse tick
        static ArrayList<Entity> parseTicks(String in) throws JSONException {

            JSONObject root = new JSONObject(in);
            JSONArray personArray = root.getJSONArray("persons");

            for (int i = 0; i < personArray.length(); i++) {
                JSONObject personsJSONObject = personArray.getJSONObject(i);

            }
            return null;
        }

        // parse Observations
        static ArrayList<Entity> parseObservations(String in) throws JSONException {

            JSONObject root = new JSONObject(in);
            JSONArray personArray = root.getJSONArray("persons");

            for (int i = 0; i < personArray.length(); i++) {
                JSONObject personsJSONObject = personArray.getJSONObject(i);


            }

            return null;
        }

        // parse Activities
        static ArrayList<Entity> parseActivities(String in) throws JSONException {

            JSONObject root = new JSONObject(in);
            JSONArray personArray = root.getJSONArray("persons");

            for (int i = 0; i < personArray.length(); i++) {
                JSONObject personsJSONObject = personArray.getJSONObject(i);

            }


            return null;
        }
    }
}
/*
    static ArrayList<Person> parsePerson(String in) throws JSONException {
        ArrayList<Person> personsList = new ArrayList<>();

        JSONObject root = new JSONObject(in);
        JSONArray personArray = root.getJSONArray("persons");

        for (int i = 0; i < personArray.length(); i++) {
            JSONObject personsJSONObject = personArray.getJSONObject(i);

            Person person = Person.createPersonFactory(personsJSONObject);
            personsList.add(person);
        }

        return personsList;
    }*/
@@ -795,38 +795,37 @@
       JSONArray 
-p
+us
 ers
-on
 Array = root.get
@@ -871,38 +871,37 @@
 (int i = 0; i %3C 
-p
+us
 ers
-on
 Array.length(); 
@@ -946,38 +946,37 @@
 onsJSONObject = 
-p
+us
 ers
-on
 Array.getJSONObj
@@ -976,33 +976,32 @@
 JSONObject(i);%0A%0A
-%0A
             %7D%0A%0A 
@@ -1200,38 +1200,37 @@
       JSONArray 
-person
+ticks
 Array = root.get
@@ -1276,38 +1276,37 @@
 (int i = 0; i %3C 
-person
+ticks
 Array.length(); 
@@ -1351,38 +1351,37 @@
 onsJSONObject = 
-person
+ticks
 Array.getJSONObj
@@ -1456,27 +1456,25 @@
 / parse 
-Observation
+Activitie
 s%0A      
@@ -1509,19 +1509,17 @@
 arse
-Observation
+Activitie
 s(St
@@ -1615,38 +1615,42 @@
       JSONArray 
-person
+activities
 Array = root.get
@@ -1696,38 +1696,42 @@
 (int i = 0; i %3C 
-person
+activities
 Array.length(); 
@@ -1776,38 +1776,42 @@
 onsJSONObject = 
-person
+activities
 Array.getJSONObj
@@ -1819,17 +1819,16 @@
 ct(i);%0A%0A
-%0A
         
@@ -1883,33 +1883,35 @@
    // parse 
-Activitie
+Observation
 s%0A        st
@@ -1934,33 +1934,35 @@
 ntity%3E parse
-Activitie
+Observation
 s(String in)
@@ -2050,38 +2050,44 @@
       JSONArray 
-pers
+observati
 on
+s
 Array = root.get
@@ -2133,38 +2133,44 @@
 (int i = 0; i %3C 
-pers
+observati
 on
+s
 Array.length(); 
@@ -2215,38 +2215,44 @@
 onsJSONObject = 
-pers
+observati
 on
+s
 Array.getJSONObj
@@ -2252,32 +2252,33 @@
 JSONObject(i);%0A%0A
+%0A
             %7D%0A%0A%0A
@@ -2276,17 +2276,16 @@
      %7D%0A%0A
-%0A
         
@@ -2307,24 +2307,25 @@
 ;%0A        %7D%0A
+%0A
     %7D%0A%7D%0A/*%0A 

build a generic JSON Util class for all entities