package com.monterojavier.javier.dexter.berry.berry_flavor;

import com.monterojavier.javier.dexter.common_model.Name;
import com.monterojavier.javier.dexter.common_model.NamedAPIResource;
import com.monterojavier.javier.dexter.contest.contest_type.ContestType;

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

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by javier on 5/19/17.
 */
//refer to http://pokeapi.co/docsv2/#berry-flavors
//GET api/v2/berry-flavor/{id or name}
public class BerryFlavor {
    private int id; //The identifier for this berry flavor resource
    private String name; //The name for this berry flavor resource
    private List<FlavorBerryMap> berries = new ArrayList<>(); //A list of the berries with this flavor
    private NamedAPIResource contest_type; //The contest type that correlates with this berry flavor
    private List<Name> names = new ArrayList<>(); //The name of this berry flavor listed in different languages

    public BerryFlavor(JSONObject berryFlavorObject){
        try{
            setId(berryFlavorObject.getInt("id"));
            setName(berryFlavorObject.getString("name"));

            JSONArray berriesArray = berryFlavorObject.getJSONArray("berries");
            for(int i = 0; i < berriesArray.length(); i++){
                setBerries(berriesArray.getJSONObject(i));
            }

            setContest_type(berryFlavorObject.getJSONObject("contest_type"));

            JSONArray namesArray = berryFlavorObject.getJSONArray("names");
            for(int i = 0; i < namesArray.length(); i++){
                setNames(namesArray.getJSONObject(i));
            }
        }catch(JSONException e){
            e.printStackTrace();
        }
    }
    public void setId(int id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setBerries(JSONObject berriesObject) {
        this.berries.add(new FlavorBerryMap(berriesObject));
    }

    public void setContest_type(JSONObject contest_typeObject) {
        this.contest_type = new NamedAPIResource(contest_typeObject);
    }

    public void setNames(JSONObject namesObject) {
        this.names.add(new Name(namesObject));
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public List<FlavorBerryMap> getBerries() {
        return berries;
    }

    public NamedAPIResource getContest_type() {
        return contest_type;
    }

    public List<Name> getNames() {
        return names;
    }
}
