package com.peetz.comics.service;

import java.util.Collection;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

import com.peetz.comics.entity.ArtistEntity;
import com.peetz.comics.entity.ComicEntity;
import com.peetz.comics.entity.IssueEntity;
import com.peetz.comics.entity.PublisherEntity;
import com.peetz.comics.entity.StoryArcEntity;
import java.util.ArrayList;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless(name="ComicService")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class ComicServiceImpl implements ComicService {
    
    @PersistenceContext(unitName = "kontor")
    private EntityManager em;

    @SuppressWarnings("unchecked")
	@Override
    public Collection<ComicEntity> getAllComics() {
        Query query = em.createNamedQuery("Comic.findAll");
        ArrayList<ComicEntity> comicList = new ArrayList<ComicEntity>(query.getResultList());
        return comicList;
    }

    @Override
    public Collection<PublisherEntity> getAllPublisher() {
        Query query = em.createNamedQuery("Publisher.findAll");
        @SuppressWarnings("unchecked")
		ArrayList<PublisherEntity> publisherList = new ArrayList<PublisherEntity>(query.getResultList());
        return publisherList;
    }

    @SuppressWarnings("unchecked")
	@Override
    public Collection<ArtistEntity> getAllArtists() {
        Query query = em.createNamedQuery("Artist.findAll");
        ArrayList<ArtistEntity> artistList = new ArrayList<ArtistEntity>(query.getResultList());
        return artistList;
    }

	@Override
	public Collection<IssueEntity> getAllIssuesForComic(ComicEntity comic) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Collection<StoryArcEntity> getAllStoryArcs() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void addStoryArc(String title) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addPublisher(String name) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public ComicEntity addComic(String title) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public PublisherEntity getPublisherById(String nodeValue) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void assignPublisher(ComicEntity comic, PublisherEntity publisher) {
		// TODO Auto-generated method stub
		
	}

}
