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

package converter;

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;
import model.Personne;

/**
 *
 * @author michel
 */

@XmlRootElement(name = "personnes")
public class PersonnesConverter {
    private Collection<Personne> entities;
    private Collection<PersonneConverter> items;
    private URI uri;
    private int expandLevel;
  
    /** Creates a new instance of PersonnesConverter */
    public PersonnesConverter() {
    }

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

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

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

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

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