package edu.duke.cabig.c3pr.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import com.semanticbits.coppa.domain.annotations.RemoteProperty;

/**
 * @author Priyatam
 */
@Entity
@Table(name = "research_staff")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@GenericGenerator(name = "id-generator", strategy = "native", parameters = { @Parameter(name = "sequence", value = "research_staff_id_seq") })
public abstract class ResearchStaff extends User {

    private List<StudyPersonnel> studyPersonnels = new ArrayList<StudyPersonnel>();

    private String nciIdentifier;
    
    private String fullName;

    private HealthcareSite healthcareSite;
    
    private List<UserBasedRecipient> userBasedRecipient;
    
    protected List<ResearchStaff> externalResearchStaff = new ArrayList<ResearchStaff>();
    
	public ResearchStaff() {
		super();
	}
	
	@Transient
	public List<ResearchStaff> getExternalResearchStaff() {
		return externalResearchStaff;
	}

	public void setExternalResearchStaff(List<ResearchStaff> externalResearchStaff) {
		this.externalResearchStaff = externalResearchStaff;
	}
	
	public void addExternalResearchStaff(ResearchStaff externalResearchStaff){
	    	this.getExternalResearchStaff().add(externalResearchStaff);
	    }


	public void addStudyPersonnel(StudyPersonnel studyPersonnel) {
        getStudyPersonnels().add(studyPersonnel);
    }

    // / BEAN METHODS

    @OneToMany(mappedBy = "researchStaff")
    @Cascade(value = { CascadeType.ALL, CascadeType.DELETE_ORPHAN })
    public List<StudyPersonnel> getStudyPersonnels() {
        return studyPersonnels;
    }

    public void setStudyPersonnels(List<StudyPersonnel> studyPersonnels) {
        this.studyPersonnels = studyPersonnels;
    }

    @OneToMany
    @Cascade(value = { CascadeType.ALL, CascadeType.DELETE_ORPHAN })
    @JoinColumn(name = "RS_ID")
    @OrderBy("id")
    public List<ContactMechanism> getContactMechanisms() {
        return contactMechanisms;
    }

    public void setContactMechanisms(List<ContactMechanism> contactMechanisms) {
        this.contactMechanisms = contactMechanisms;
    }

    @ManyToOne
    @JoinColumn(name = "HCS_ID")
    public HealthcareSite getHealthcareSite() {
        return healthcareSite;
    }

    public void setHealthcareSite(HealthcareSite healthcareSite) {
        this.healthcareSite = healthcareSite;
    }

    public int compareTo(Object o) {
        if (this.equals((ResearchStaff) o)) return 0;
        else return 1;
    }

    @Override
    public int hashCode() {
        final int PRIME = 31;
        // int result = super.hashCode();
        int result = 1;
        result = PRIME * result + ((nciIdentifier == null) ? 0 : nciIdentifier.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (getClass() != obj.getClass()) return false;
        final ResearchStaff other = (ResearchStaff) obj;
        if (nciIdentifier == null) {
            if (other.nciIdentifier != null) return false;
        }
        else if (!nciIdentifier.equalsIgnoreCase(other.nciIdentifier)) return false;
        return true;
    }

    @RemoteProperty
    public String getNciIdentifier() {
        return nciIdentifier;
    }

    public void setNciIdentifier(String nciIdentifier) {
        this.nciIdentifier = nciIdentifier;
    }

    @OneToMany
    @Cascade(value = { CascadeType.LOCK})
    @JoinColumn(name = "research_staff_id")
	public List<UserBasedRecipient> getUserBasedRecipient() {
		return userBasedRecipient;
	}

	public void setUserBasedRecipient(List<UserBasedRecipient> userBasedRecipient) {
		this.userBasedRecipient = userBasedRecipient;
	}
	
}
@@ -1137,40 +1137,8 @@
   %0D%0A
-    private String fullName;%0D%0A%0D%0A
     

test case coverage improvement