package com.moac.android.opensecretsanta.model;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = DrawResultEntry.TABLE_NAME)
public class DrawResultEntry extends PersistableObject {

    public static final String TABLE_NAME =  "draw_result_entries";

    public static final long UNSET_DATE = -1;

    public static interface Columns extends PersistableObject.Columns {
        public static final String DRAW_RESULT_ID_COLUMN = "DRAW_RESULT_ID";
        public static final String GIVER_MEMBER_ID_COLUMN = "GIVER_MEMBER_ID";
        public static final String RECEIVER_MEMBER_ID_COLUMN = "RECEIVER_MEMBER_ID";
        public static final String VIEWED_DATE_COLUMN = "VIEWED_DATE";
        public static final String SENT_DATE_COLUMN = "SENT_DATE";
        public static final String SEND_STATUS_COLUMN = "SEND_STATUS";
    }

    /**
     * Unique combo with mGiver and mDrawResult only prevents a giver having multiple recipients,
     * rather than a recipient having multiple givers. I don't think there's a way to support
     * two separate combos in ORMLite - eg mGiver/mDrawResult & mReceiver/mDrawResult.
     *
     * Perhaps this is an argument for is associating the DRE with the Members only and
     * not also the DrawResult (which perhaps could be discarded)
     */

    @DatabaseField(columnName = Columns.GIVER_MEMBER_ID_COLUMN, foreign = true, canBeNull = false, uniqueCombo = true,
      columnDefinition = "integer references members (_id) on delete cascade")
    private Member mGiver;

    @DatabaseField(columnName = Columns.RECEIVER_MEMBER_ID_COLUMN, foreign = true, canBeNull = false,
      columnDefinition = "integer references members (_id) on delete cascade")
    private Member mReceiver;

    @DatabaseField(columnName = Columns.VIEWED_DATE_COLUMN)
    private long mViewedDate = UNSET_DATE;

    @DatabaseField(columnName = Columns.SENT_DATE_COLUMN)
    private long mSentDate = UNSET_DATE;

    @DatabaseField(columnName = Columns.SEND_STATUS_COLUMN)
    private long mSendStatus;

    @DatabaseField(columnName = Columns.DRAW_RESULT_ID_COLUMN, foreign = true, canBeNull = false, uniqueCombo = true,
      columnDefinition = "integer references draw_results (_id) on delete cascade")
    private DrawResult mDrawResult;

    public long getDrawResultId() { return mDrawResult.getId(); }
    public void setDrawResult(DrawResult _drawResult) { mDrawResult = _drawResult; }

    public long getGiverMemberId() { return mGiver.getId(); }
    public void setGiverMember(Member _giver) { mGiver = _giver; }

    public long getReceiverMemberId() { return mReceiver.getId(); }
    public void setReceiverMember(Member _receiver) { mReceiver = _receiver; }

    public long getViewedDate() { return mViewedDate; }
    public void setViewedDate(long _viewedDate) { mViewedDate = _viewedDate; }

    public long getSentDate() { return mSentDate; }
    public void setSentDate(long _sentDate) { mSentDate = _sentDate; }

    public long getSendStatus() { return mSendStatus; }
    public void setSendStatus(long _sendStatus) { mSendStatus = _sendStatus; }

}

@@ -246,16 +246,252 @@
 ject %7B%0A%0A
+    public enum Status %7B%0A        Not_Sent(%22Not Sent%22), Successful(%22Successful%22), Failed(%22Failed%22);%0A%0A        private String mText;%0A        Status(String _text) %7B  mText = _text; %7D%0A        public String getText() %7B return mText; %7D%0A    %7D%0A%0A
     publ
@@ -550,16 +550,16 @@
 tries%22;%0A
-
 %0A    pub
@@ -1146,16 +1146,15 @@
   * 
-U
+u
 nique
- c
+C
 ombo
@@ -2017,24 +2017,263 @@
 mReceiver;%0A%0A
+    @DatabaseField(columnName = Columns.DRAW_RESULT_ID_COLUMN, foreign = true, canBeNull = false, uniqueCombo = true,%0A      columnDefinition = %22integer references draw_results (_id) on delete cascade%22)%0A    private DrawResult mDrawResult;%0A%0A
     @Databas
@@ -2532,28 +2532,30 @@
     private 
-long
+Status
  mSendStatus
@@ -2558,246 +2558,25 @@
 atus
-;%0A%0A    @DatabaseField(columnName = Columns.DRAW_RESULT_ID_COLUMN, foreign = true, canBeNull = false, uniqueCombo = true,%0A      columnDefinition = %22integer references draw_results (_id) on delete cascade%22)%0A    private DrawResult mDrawResul
+ = Status.Not_Sen
 t;%0A%0A
@@ -3272,28 +3272,30 @@
 %0A    public 
-long
+Status
  getSendStat
@@ -3353,20 +3353,22 @@
 dStatus(
-long
+Status
  _sendSt

Make DrawResultEntry status an enum.