package com.ibtp.kontor.comics.entity;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;

/**
 * Created by TPEETZ on 16.01.2015.
 */
@NamedQueries({
        @NamedQuery(name="Artist.findAll", query="SELECT a from ArtistEntity as a"),
        @NamedQuery(name="Artist.findByName", query="SELECT a from ArtistEntity as a WHERE a.name = :name")
})

@Entity
@Table(name="ARTIST")
public class ArtistEntity {

    private Long id;

    private String name;

    private Collection<IssueEntity> writtenIssues = new ArrayList<IssueEntity>();

    private Collection<IssueEntity> inkedIssues = new ArrayList<IssueEntity>();

    private Collection<IssueEntity> penciledIssues = new ArrayList<IssueEntity>();

    public ArtistEntity(String name) {
        setName(name);
    }

    public ArtistEntity() {}

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    Long getId() { return id; }

    @SuppressWarnings("unused")
    private void setId(Long id) { this.id = id; }

    @Column
    String getName() { return name; }

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

    public void setWrittenIssues(Collection<IssueEntity> writtenIssues) { this.writtenIssues = writtenIssues; }

    @OneToMany(mappedBy="writer", cascade=CascadeType.REMOVE)
    public Collection<IssueEntity> getWrittenIssues() {
        return writtenIssues;
    }

    public void setInkedIssues(Collection<IssueEntity> inkedIssues) { this.inkedIssues = inkedIssues; }

    @OneToMany(mappedBy="inker", cascade=CascadeType.REMOVE)
    public Collection<IssueEntity> getInkedIssues() {
        return inkedIssues;
    }

    public void setPenciledIssues(Collection<IssueEntity> penciledIssues) { this.penciledIssues = penciledIssues; }

    @OneToMany(mappedBy="penciler", cascade=CascadeType.REMOVE)
    public Collection<IssueEntity> getPenciledIssues() {
        return penciledIssues;
    }

    @Override
    public String toString() {
        return "Artist[" + "id=" + getId() + ",name=" + getName() + "]";
    }
}
