package zafrani.com.pubgapp.utils;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import zafrani.com.pubgapp.models.Category;
import zafrani.com.pubgapp.models.Item;
import zafrani.com.pubgapp.models.Items;
import zafrani.com.pubgapp.models.Type;

public class FileUtil {

    @Nullable
    public static Items getItems(@NonNull final Activity activity) throws IOException {
        final InputStream inputStream = activity.getAssets().open("items.json");

        if (inputStream != null) {
            final Gson gson = new Gson();
            final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

            return gson.fromJson(reader, Items.class);
            /*
            Items items = gson.fromJson(reader, Items.class);
            return bindInfo(items);
             */
        }
        return null;
    }



    public static Items bindInfo(@NonNull final Items items) {
        for (Category category: items.getCategories()){
            Log.e("BINDINGINFO", "Category: " +category);

            for (Type type: category.getTypes()){

                Log.e("BINDINGINFO", "Type: " +type);
                for (Item item: type.getItems()) {
                    item.setCategory(category.getName());
                    item.setType(type.getType_name());
                }
            }
        }
        return items;
    }
}

@@ -148,33 +148,8 @@
 ble;
-%0Aimport android.util.Log;
 %0A%0Aim
@@ -872,495 +872,264 @@
 urn 
-gson.fromJson(reader, Items.class);%0A            /*%0A            Items items = gson.fromJson(reader, Items.class);%0A            return bindInfo(items);%0A             */%0A        %7D%0A        return null;%0A    %7D%0A%0A%0A%0A    public static Items bindInfo(@NonNull final Items items) %7B%0A        for (Category category: items.getCategories())%7B%0A            Log.e(%22BINDINGINFO%22, %22Category: %22 +category);%0A%0A            for (Type type: category.getTypes())%7B%0A%0A                Log.e(%22BINDINGINFO%22, %22Type: %22 +type);
+bindInfo(gson.fromJson(reader, Items.class));%0A%0A        %7D%0A        return null;%0A    %7D%0A%0A%0A%0A    public static Items bindInfo(@NonNull final Items items) %7B%0A        for (Category category: items.getCategories())%7B%0A%0A            for (Type type: category.getTypes())%7B
 %0A   

correct binding of type and category to each item