package com.monterojavier.javier.dexter.pokemon;

import com.monterojavier.javier.dexter.common_model.Name;
import com.monterojavier.javier.dexter.common_model.NamedAPIResource;
import com.monterojavier.javier.dexter.pokemon.species.PokemonSpecies;

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

import java.util.ArrayList;
import java.util.List;

/**
 * Created by javier on 5/19/17.
 */
//refer to http://pokeapi.co/docsv2/#egg-groups
//GET api/v2/egg-group/{id or name}
public class EggGroup {
    private int id; //The identifier for this egg group resource
    private String name; //The name for this egg group resource
    private List<Name> names = new ArrayList<>(); //The name of this egg group listed in different languages
    private List<NamedAPIResource> pokemon_species = new ArrayList<>(); //A list of all Pokémon species that are members of this egg group

    public EggGroup(JSONObject eggGroupObject){
        try {
            setId(eggGroupObject.getInt("id"));
            setName(eggGroupObject.getString("name"));

            JSONArray namesArray = eggGroupObject.getJSONArray("names");
            for(int i = 0; i < namesArray.length(); i++){
                setNames(namesArray.getJSONObject(i));
            }

            JSONArray pokemon_speciesArray = eggGroupObject.getJSONArray("pokemon_species");
            for(int i = 0; i < pokemon_speciesArray.length(); i++){
                setPokemon_species(pokemon_speciesArray.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 setNames(JSONObject namesObject) {
        this.names.add(new Name(namesObject));
    }

    public void setPokemon_species(JSONObject pokemon_speciesObject) {
        this.pokemon_species.add(new NamedAPIResource(pokemon_speciesObject));
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

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

    public List<NamedAPIResource> getPokemon_species() {
        return pokemon_species;
    }
}