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

package converter;

import TestRest.Arrival;
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 java.util.ArrayList;

/**
 *
 * @author aparnab
 */

@XmlRootElement(name = "arrivals")
public class ArrivalsConverter {
    private Collection<Arrival> entities;
    private Collection<ArrivalConverter> items;
    private URI uri;
    private int expandLevel;
  
    /** Creates a new instance of ArrivalsConverter */
    public ArrivalsConverter() {
    }

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

    /**
     * Returns a collection of ArrivalConverter.
     *
     * @return a collection of ArrivalConverter
     */
    @XmlElement
    public Collection<ArrivalConverter> getArrival() {
        if (items == null) {
            items = new ArrayList<ArrivalConverter>();
        }
        if (entities != null) {
            items.clear();
            for (Arrival entity : entities) {
                items.add(new ArrivalConverter(entity, uri, expandLevel, true));
            }
        }
        return items;
    }

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

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

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