/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TestRest.converter;

import TestRest.QuakemlView;
import TestRest.QuakemlViewNG;
import java.net.URI;
import java.util.Collection;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.ws.rs.Path;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author aparnab
 */

//@Path("/events/")
@XmlRootElement(name = "quakeml")
public class QuakemlViewsConverter {
    @XmlAttribute
    private String xmlns = "http://quakeml.org/xmlns/quakeml/1.1";

    //private Collection<QuakemlView> entities;
    private Collection<QuakemlViewNG> entities;
    //private Collection<QuakemlViewConverter> items;
    //@XmlElement(name="eventParameters")
    //private Collection<EventParameterConverter> items;
    //private List<EventParameterConverter> items;
    private EventParameterConverter items;
    private URI uri;
    private int expandLevel;
  
    /** Creates a new instance of QuakemlViewsConverter */
    public QuakemlViewsConverter() {
    }

    /**
     * Creates a new instance of QuakemlViewsConverter.
     *
     * @param entities associated entities
     * @param uri associated uri
     * @param expandLevel indicates the number of levels the entity graph should be expanded
     */
    public QuakemlViewsConverter(Collection<QuakemlViewNG> entities, URI uri, int expandLevel) {
    //public QuakemlViewsConverter(Collection<QuakemlView> entities, URI uri, int expandLevel) {
        this.entities = entities;
        this.uri = uri;
        this.expandLevel = expandLevel;
        getQuakemlView();
    }

    /**
     * Returns a collection of QuakemlViewConverter.
     *
     * @return a collection of QuakemlViewConverter
     */
    @XmlElement(name="eventParameters")
    //public Collection<QuakemlViewConverter> getQuakemlView() {
    //public Collection<EventParameterConverter> getQuakemlView() {
    public EventParameterConverter getQuakemlView() {
        if (items == null) {
            //items = new ArrayList<QuakemlViewConverter>();
            //items = new ArrayList<EventParameterConverter>();
            items = new EventParameterConverter();
        }
        if (entities != null) {
            items = new EventParameterConverter(entities, uri, expandLevel, true);
            //items.clear();
            //for (QuakemlView entity : entities) {
                //items.add(new QuakemlViewConverter(entity, uri, expandLevel, true));
                //items.add(new EventParameterConverter(entity, uri, expandLevel, true));
            //}
        }
        return items;
    }

    /**
     * Sets a collection of QuakemlViewConverter.
     *
     * @param a collection of QuakemlViewConverter to set
     */
    //public void setQuakemlView(Collection<QuakemlViewConverter> items) {
    //public void setQuakemlView(Collection<EventParameterConverter> items) {
    //public void setQuakemlView(List<EventParameterConverter> items) {
    public void setQuakemlView(EventParameterConverter items) {
        this.items = items;
    }

    /**
     * Returns the URI associated with this converter.
     *
     * @return the uri
     */
    @XmlAttribute
    public URI getUri() {
        return uri;
    }

    /**
     * Returns a collection QuakemlView entities.
     *
     * @return a collection of QuakemlView entities
     */
    /*
    @XmlTransient
    public Collection<QuakemlView> getEntities() {
        entities = new ArrayList<QuakemlView>();
        if (items != null) {
            //for (QuakemlViewConverter item : items) {
            for (EventParameterConverter item : items) {
                entities.add(item.getEntity());
            }
        }
        return entities;
    }*/
}
