package com.maxiee.heartbeat.database.api;

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

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

import java.util.ArrayList;

/**
 * Created by maxiee on 15-6-16.
 */
public class AddLabelsApi extends BaseDBApi{

    private ArrayList<String> mLabels;

    public AddLabelsApi(Context context,
                        ArrayList<String> labels) {
        super(context);
        mLabels = labels;
    }

    public int insertLabel(String label) {
        ContentValues values = new ContentValues();
        values.put(LabelsTable.LABEL, label);
        return (int) add(LabelsTable.NAME, values);
    }

    public ArrayList<Integer> exec() {
        ArrayList<Integer> ret = new ArrayList<>();
        for (String label: mLabels) {
            int id = new HasLabelApi(mContext, label).exec();
            if (id == HasLabelApi.NOT_FOUND) { // insert into DB
                int insertedId = insertLabel(label);
                ret.add(insertedId);
            } else {
                ret.add(id);
            }
        }
        return ret;
    }
}

@@ -232,16 +232,48 @@
 5-6-16.%0A
+ *%0A * TODO: need an AddLabelApi%0A
  */%0Apubl
@@ -496,32 +496,209 @@
  labels;%0A    %7D%0A%0A
+    public AddLabelsApi(Context context,%0A                        String label) %7B%0A        super(context);%0A        mLabels = new ArrayList%3C%3E();%0A        mLabels.add(label);%0A    %7D%0A%0A
     public int i

add a constructor for single String.