
package co.louiscap.entwasums.ents;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotNull;

/**
 * @author Louis Capitanchik
 */
@Entity
public class Idea implements Serializable {
    private static final long serialVersionUID = -9120642761390692070L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @NotNull
    private Long id;

    @NotNull
    private String title;
    
    private String description;
    
    @ManyToMany
    private List<Interactor> assignees;
    
    @NotNull
    @ManyToOne
    private Interactor creator;
    
    @OneToOne(mappedBy = "project")
    private Student implementor;
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    public String getTitle() {
        return title;
    }

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

    public String getDescription() {
        return description;
    }

    public void setDescription(String desccription) {
        this.description = desccription;
    }

    public List<Interactor> getAssigned() {
        return assignees;
    }

    public void setAssigned(List<Interactor> assignees) {
        this.assignees = assignees;
    }

    public Interactor getCreator() {
        return creator;
    }

    public void setCreator(Interactor creator) {
        this.creator = creator;
    }

    public Interactor getImplementor() {
        return implementor;
    }

    public void setImplementor(Student implementor) {
        this.implementor = implementor;
    }
    
    public boolean isByOrganisation() {
        return creator instanceof Organisation;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Idea)) {
            return false;
        }
        Idea other = (Idea) object;
        return this.id.equals(other.id);
    }

    @Override
    public String toString() {
        return "co.louiscap.entwasums.entities.Idea[ id=" + id + " ]";
    }
    
}
