package com.peetz.kontor.data;

import java.util.Collection;
import java.util.Iterator;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.peetz.medien.entity.AudioCDEntity;
import com.peetz.medien.entity.BoxSetEntity;
import com.peetz.medien.entity.FilmEntity;
import com.peetz.medien.service.MedienService;

public class ExportMedien
{
	public Element backupMedien(Document document)
	{
		Element medien = document.createElement("medien");
		medien.appendChild(document.createTextNode("\n"));
		
		MedienService medienService = getMedienService();

		Collection<AudioCDEntity> cds = medienService.getAllCDs();
		Iterator<AudioCDEntity> iterator_cds = cds.iterator();
		while(iterator_cds.hasNext()) {
			AudioCDEntity cd = iterator_cds.next();
			Element cdNode = document.createElement("audioCD");
			//cdNode.setAttribute("id", cd.getId());
			//cdNode.setAttribute("album", cd.getAlbum());
			//cdNode.setAttribute("artist", cd.getArtist());
			medien.appendChild(cdNode);
			medien.appendChild(document.createTextNode("\n"));
		}

		Collection<FilmEntity> films = medienService.getAllDVDs();
		Iterator<FilmEntity> iterator_films = films.iterator();
		while(iterator_films.hasNext()) {
			FilmEntity film = iterator_films.next();
			Element filmNode = document.createElement("film");
			//filmNode.setAttribute("id", film.getId());
			//filmNode.setAttribute("title", film.getTitle());
			medien.appendChild(filmNode);
			medien.appendChild(document.createTextNode("\n"));
		}

		Collection<BoxSetEntity> boxsets = medienService.getAllBoxSets();
		Iterator<BoxSetEntity> iterator_boxsets = boxsets.iterator();
		while(iterator_boxsets.hasNext()) {
			BoxSetEntity boxSet = iterator_boxsets.next();
			Element boxNode = document.createElement("boxSet");
			boxNode.setAttribute("id", boxSet.getId().toString());
			boxNode.setAttribute("title", boxSet.getTitle());
			films = boxSet.getFilms();
			iterator_films = films.iterator();
			if (iterator_films.hasNext()) {
				boxNode.appendChild(document.createTextNode("\n"));
			}
			while(iterator_films.hasNext()) {
				FilmEntity film = iterator_films.next(); 
				Element filmNode = document.createElement("film");
				//filmNode.setAttribute("id", film.getId());
				boxNode.appendChild(filmNode);
				boxNode.appendChild(document.createTextNode("\n"));
			}
			medien.appendChild(boxNode);
			medien.appendChild(document.createTextNode("\n"));
		}
		return medien;
	}

	private MedienService getMedienService()
	{
		return null;
	}
}
