package com.peetz.comics.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.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@NamedQueries({
	@NamedQuery(name="Comic.findAll", query="SELECT c from ComicEntity as c"),
	@NamedQuery(name="Comic.findByTitle", query="SELECT c from ComicEntity as c WHERE c.title = :title")
})

@Entity
@Table(name="COMIC")
public class ComicEntity
{
    private Long id;

    private String title;

    private Boolean completed;

    private Boolean currentOrder;

    private Collection<IssueEntity> issues = new ArrayList<IssueEntity>();
	
    private Collection<StoryArcEntity> storyArc = new ArrayList<StoryArcEntity>();

    private Collection<VolumeEntity> volumes = new ArrayList<VolumeEntity>();

    public PublisherEntity publisher;

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

    @Column
    public String getTitle() { return title; }

    public void setTitle(String title) { this.title = title; }

    @Column
    public Boolean getCompleted() { return completed; }

    public Boolean isCompleted() { return completed; }
	
    public void setCompleted(Boolean completed) { this.completed = completed; }
	
    @Column
    public Boolean getCurrentOrder() { return currentOrder; }

    public Boolean isCurrentOrder() { return currentOrder; }

    public void setCurrentOrder(Boolean currentOrder) { this.currentOrder = currentOrder; }

    public void setIssues(Collection<IssueEntity> issues) { this.issues = issues; }

    @OneToMany(mappedBy="comic", cascade=CascadeType.REMOVE)
    public Collection<IssueEntity> getIssues() { return issues; }

    public void setStoryArc(Collection<StoryArcEntity> storyArc) { this.storyArc = storyArc; }
    
    @OneToMany(mappedBy="comic", cascade=CascadeType.REMOVE)
    public Collection<StoryArcEntity> getStoryArc() { return storyArc; }

    public void setVolumes(Collection<VolumeEntity> volumes) { this.volumes = volumes; }
    
    @OneToMany(mappedBy="comic", cascade=CascadeType.REMOVE)
    public Collection<VolumeEntity> getVolumes() { return volumes; }
    
    @ManyToOne
    public PublisherEntity getPublisher() { return publisher; }

    public void setPublisher(PublisherEntity publisher) {
        this.publisher = publisher;
    }
}
