package org.msh.tb.entities;

import org.hibernate.validator.NotNull;
import org.msh.etbm.commons.transactionlog.mapping.PropertyLog;

import javax.persistence.*;

@Entity
@Table(name = "casecomorbidity")
public class CaseComorbidity implements Transactional, SyncKey {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @ManyToOne
    @JoinColumn(name = "CASE_ID")
    @NotNull
    private TbCase tbcase;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COMORBIDITY_ID")
    @NotNull
    FieldValue comorbidity;

    @Embedded
    @AssociationOverrides({ @AssociationOverride(name = "value", joinColumns = @JoinColumn(name = "COMORB_ID")) })
    @AttributeOverrides({ @AttributeOverride(name = "complement", column = @Column(name = "otherCaseComorbidity")) })

    private FieldValueComponent comorb;

    @Column(length = 100)
    private String duration;

    @Column(length = 200)
    private String comment;

    /**
     * Point to the transaction log that contains information about the last time this entity was changed (updated or created)
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "lastTransaction_ID")
    @PropertyLog(ignore = true)
    private TransactionLog lastTransaction;

    // Ricardo: TEMPORARY UNTIL A SOLUTION IS FOUND. Just to attend a request from the XML data model to
    // map an XML node to a property in the model
    @Transient
    private Integer clientId;

    /**
     * @return
     */
    public Integer getClientId() {
        return clientId;
    }

    /**
     * @param clientId
     */
    public void setClientId(Integer clientId) {
        this.clientId = clientId;
    }


    /**
     * @return the id
     */
    public Integer getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * @return the comment
     */
    public String getComment() {
        return comment;
    }

    /**
     * @param comment the comment to set
     */
    public void setComment(String comment) {
        this.comment = comment;
    }

    /**
     * @return the tbcase
     */
    public TbCase getTbcase() {
        return tbcase;
    }

    /**
     * @param tbcase the tbcase to set
     */
    public void setTbcase(TbCase tbcase) {
        this.tbcase = tbcase;
    }

    /**
     * @return the comorbidity
     */
    public FieldValue getComorbidity() {
        return comorbidity;
    }

    /**
     * @param comorbidity the comorbidity to set
     */
    public void setComorbidity(FieldValue comorbidity) {
        this.comorbidity = comorbidity;
    }

    /**
     * @return the duration
     */
    public String getDuration() {
        return duration;
    }

    /**
     * @param duration the duration to set
     */
    public void setDuration(String duration) {
        this.duration = duration;
    }

    public FieldValueComponent getComorb() {
        if (comorb == null)
            comorb = new FieldValueComponent();
        return comorb;
    }

    public void setComorb(FieldValueComponent comorb) {
        this.comorb = comorb;
    }

    /**
     * @return the lastTransaction
     */
    @Override
    public TransactionLog getLastTransaction() {
        return lastTransaction;
    }

    /**
     * @param lastTransaction the lastTransaction to set
     */
    @Override
    public void setLastTransaction(TransactionLog lastTransaction) {
        this.lastTransaction = lastTransaction;
    }
}
