/*
 * This file is part of DebGen Biobank Software developed by ASTRID Research.
 * All rights reserved. Reproduction, modification, use or disclosure
 * to third parties without express authority is forbidden.
 *
 * Copyright ASTRID Research Inc., Hungary, 2009-2011.
 *
 * ASTRID Research
 * Headquaters: Csapo utca 42. Debrecen H-4029 HUNGARY
 * Phone: +36-52-533-173        Fax: +36-52-533-174
 * Web: http://www.astrid.hu    E-mail: info@astrid.hu
 *
 * Project name: DebGen Biobank Software project.
 * URLS:
 * Developers: Istvan Zoltan Nagy (istvan.nagy@astrid.hu)
 */

package hu.astrid.debgen.patientmanagement.domain.sample;

import hu.astrid.debgen.patientmanagement.domain.modules.requests.AnalysisRequest;
import hu.astrid.toucan.control.bean.ToucanBean;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: inagy
 * Date: Jun 30, 2010
 * Time: 10:10:40 AM
 */
@Entity
@Table(name = "debgen_sample")
public class Sample implements ToucanBean, Serializable, Comparable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(nullable = false, length = 20) //TODO: should be unique later, but that was so useless this time...
    private String sampleCode;
    @ManyToOne(fetch = FetchType.EAGER)
    private AnalysisRequest analysisRequest;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getSampleCode() {
        return sampleCode;
    }

    public void setSampleCode(String sampleCode) {
        this.sampleCode = sampleCode;
    }

    public AnalysisRequest getAnalysisRequest() {
        return analysisRequest;
    }

    public void setAnalysisRequest(AnalysisRequest analysisRequest) {
        this.analysisRequest = analysisRequest;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Sample sample = (Sample) o;

        if (sampleCode != null ? !sampleCode.equals(sample.sampleCode) : sample.sampleCode != null) return false;

        return true;
    }

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

    public int compareTo(Object o) {
        if (o instanceof Sample)
            return sampleCode.compareTo(((Sample) o).getSampleCode());
        else
            return 1;
    }
}
