package com.maxiee.heartbeat.database.api;

import android.content.ContentValues;
import android.content.Context;

import com.maxiee.heartbeat.database.tables.ThoughtsTable;

/**
 * Created by maxiee on 15-6-14.
 */
public class AddThoughtApi extends BaseDBApi{

    private int mEventKey;
    private String mThought;
    private Context mContext;

    public AddThoughtApi(Context context,
                         final int eventKey,
                         final String thought) {
        super(context);
        mContext = context;
        mEventKey = eventKey;
        mThought = thought;
    }

    public boolean exec() {

        ContentValues values = new ContentValues();
        values.put(ThoughtsTable.THOUGHT, mThought);
        values.put(ThoughtsTable.TIMESTAMP, System.currentTimeMillis());

        int thoughtKey = (int) add(ThoughtsTable.NAME, values);

        new AddEventThoughtRelationApi(
                mContext,
                mEventKey,
                thoughtKey).exec();

        return true;
    }
}

@@ -163,15 +163,120 @@
 ught
+Re
 sTable;
+%0Aimport com.maxiee.heartbeat.database.tables.ThoughtsTable;%0Aimport com.maxiee.heartbeat.model.Thoughts;
 %0A%0A/*
@@ -413,24 +413,79 @@
 g mThought;%0A
+    private int mResType;%0A    private String mResPath;%0A
     private 
@@ -635,16 +635,107 @@
  thought
+,%0A                         final int resType,%0A                         final String resPath
 ) %7B%0A    
@@ -836,24 +836,80 @@
  = thought;%0A
+        mResType = resType;%0A        mResPath = resPath;%0A
     %7D%0A%0A    p
@@ -1261,32 +1261,32 @@
      mEventKey,%0A
-
                 
@@ -1302,24 +1302,386 @@
 y).exec();%0A%0A
+        if (mResType == Thoughts.Thought.HAS_NO_RES) return true;%0A%0A        ContentValues resValues = new ContentValues();%0A        resValues.put(ThoughtResTable.THOUGHT_ID, thoughtKey);%0A        resValues.put(ThoughtResTable.TYPE, mResType);%0A        resValues.put(ThoughtResTable.PATH, mResPath);%0A%0A        int resKey = (int) add(ThoughtResTable.NAME, resValues);%0A%0A
         retu

add thought resource.