package com.peetz.tradingcards.service;

import com.peetz.tradingcards.dal.SportDao;
import java.util.Collection;

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

import com.peetz.tradingcards.entity.PositionEntity;
import com.peetz.tradingcards.entity.SportEntity;
import com.peetz.tradingcards.entity.TeamEntity;
import java.util.ArrayList;
import javax.ejb.EJB;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless(name="SportService")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class SportServiceImpl implements SportService {

    @PersistenceContext(unitName = "kontor")
    private EntityManager em;
    
    @EJB
    SportDao sportDao;
    
    @SuppressWarnings("unchecked")
	@Override
    public Collection<SportEntity> getAllSports() {
        Query query = em.createNamedQuery("Sport.findAll");
        ArrayList<SportEntity> sportList = new ArrayList<SportEntity>(query.getResultList());
        return sportList;
    }

    @SuppressWarnings("unchecked")
	@Override
    public Collection<TeamEntity> getAllTeams() {
        Query query = em.createNamedQuery("Team.findAll");
        ArrayList<TeamEntity> teamList = new ArrayList<TeamEntity>(query.getResultList());
        return teamList;
    }


    @Override
    public void addSport(String name) {
        SportEntity entity = new SportEntity();
        entity.setName(name);
        sportDao.store(entity);
    }

    @Override
    public Collection<TeamEntity> getTeams(SportEntity sport) {
    	return null;
    }

    @Override
    public Collection<PositionEntity> getPositions(SportEntity sport) {
    	// TODO Auto-generated method stub
    	return null;
    }
}
