package com.peetz.tradingcards.entity;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@NamedQueries({
    @NamedQuery(name="Sport.findAll", query="SELECT s from SportEntity as s"),
    @NamedQuery(name="Sport.findByName", query="SELECT s from SportEntity as s WHERE s.name = :name")
})

@Entity
@Table(name="SPORT")
public class SportEntity {
	
	private Long id;
	private String name;
	private Collection<TeamEntity> teams = new ArrayList<TeamEntity>();
	private Collection<PositionEntity> positions = new ArrayList<PositionEntity>();

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() { return id; }
	
	@SuppressWarnings("unused")
	private void setId(Long id) { this.id = id; }

	@Column
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@OneToMany(mappedBy="sport", cascade=CascadeType.REMOVE)
	public Collection<TeamEntity> getTeams() {
		return teams;
	}

	public void setTeams(Collection<TeamEntity> teams) {
		this.teams = teams;
	}

	@OneToMany(mappedBy="sport", cascade=CascadeType.REMOVE)
	public Collection<PositionEntity> getPositions() {
		return positions;
	}

	public void setPositions(Collection<PositionEntity> positions) {
		this.positions = positions;
	}
}
