package org.motechproject.mtraining.domain;

import org.motechproject.mds.annotations.Access;
import org.motechproject.mds.annotations.Entity;
import org.motechproject.mds.annotations.Field;
import org.motechproject.mds.domain.MdsEntity;
import org.motechproject.mds.util.SecurityMode;
import org.motechproject.mtraining.util.Constants;

import java.util.Objects;

/**
 * Question object with resource identifiers for question and answer
 */
@Entity
@Access(value = SecurityMode.PERMISSIONS, members = {Constants.MANAGE_MTRAINING})
public class Question extends MdsEntity {

    /**
     * Question resource identifier in the external system
     */
    @Field
    private String question;

    /**
     * Answer resource identifier in the external system
     */
    @Field
    private String answer;

    public Question() {
        this (null, null);
    }

    public Question(String question, String answer) {
        this.question = question;
        this.answer = answer;
    }

    public String getQuestion() {
        return question;
    }

    public void setQuestion(String question) {
        this.question = question;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }

        final Question other = (Question) obj;

        return Objects.equals(this.getId(), other.getId())
                && Objects.equals(this.getQuestion(), other.getQuestion())
                && Objects.equals(this.getAnswer(), other.getAnswer());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getQuestion(), getAnswer());
    }
}

@@ -331,16 +331,39 @@
 tants;%0A%0A
+import java.util.List;%0A
 import j
@@ -803,29 +803,36 @@
 private 
-String
+List%3CAnswer%3E
  answer
+s
 ;%0A%0A    p
@@ -921,29 +921,36 @@
 estion, 
-String
+List%3CAnswer%3E
  answer
+s
 ) %7B%0A    
@@ -990,32 +990,33 @@
      this.answer
+s
  = answer;%0A    %7D
@@ -1000,32 +1000,33 @@
 answers = answer
+s
 ;%0A    %7D%0A%0A    pub
@@ -1179,30 +1179,36 @@
 %0A    public 
-String
+List%3CAnswer%3E
  getAnswer()
@@ -1205,16 +1205,17 @@
 etAnswer
+s
 () %7B%0A   
@@ -1228,24 +1228,25 @@
 eturn answer
+s
 ;%0A    %7D%0A%0A   
@@ -1271,22 +1271,30 @@
 swer
-(String
+s(List%3CAnswer%3E
  answer
+s
 ) %7B%0A
@@ -1312,16 +1312,17 @@
 s.answer
+s
  = answe
@@ -1322,16 +1322,17 @@
 = answer
+s
 ;%0A    %7D%0A
@@ -1775,16 +1775,17 @@
 etAnswer
+s
 (), othe
@@ -1787,32 +1787,33 @@
  other.getAnswer
+s
 ());%0A    %7D%0A%0A    
@@ -1902,16 +1902,17 @@
 etAnswer
+s
 ());%0A   

answers for question as a List of Answer objects