package scal.io.liger.model;

import android.content.Context;
import android.util.Log;

import com.fima.cardsui.objects.Card;

import scal.io.liger.view.ProgressCardView;

public class ProgressCardModel extends CardModel {
    private String text;

    public ProgressCardModel() {
        this.type = this.getClass().getName();
    }

    @Override
    public Card getCardView(Context context) {
        return new ProgressCardView(context, this);
    }

    public String getText() {
        return fillReferences(this.text);
    }

    public void setText(String time) {
        this.text = time;
    }

    private boolean g(String ref) {
        String val = storyPathReference.getReferencedValue(ref);
        Log.d("ProgressCardModel", "ref: " + ref + ", val: " + val);
        return (val != null) && !val.equals("");
    }

    @Override
    public boolean checkReferencedValues() {
        clearValues();
        addValue("value::" + (areWeSatisfied() ? "true" : "false"), false); // FIXME this should be in a more general init() method called on each card as the path is bootstrapped

        boolean val = g(references.get(0));
        return val;
    }

    public boolean areWeSatisfied() {
        boolean result = false;

        if ((references != null) && (references.size() == 10)) { // FIXME hardcoding to 9 refs (+1 ignored) obviously sucks balls
//            result = ((g(references.get(1)) && g(references.get(2)) && g(references.get(3)))
//                || (g(references.get(4)) && g(references.get(5)) && g(references.get(6)))
//                || (g(references.get(7)) && g(references.get(8)) && g(references.get(9))));

            String medium = storyPathReference.getReferencedValue(references.get(0));

            if (medium != null) {
                // FIXME this is super fragile, assume the clip type is based on order.  ug.
                if (medium.equals("video")) {
                    result = (g(references.get(1)) && g(references.get(2)) && g(references.get(3)));
                } else if (medium.equals("audio")) {
                    result = (g(references.get(4)) && g(references.get(5)) && g(references.get(6)));
                } else if (medium.equals("photo")) {
                    result = (g(references.get(7)) && g(references.get(8)) && g(references.get(9)));
                }
            }

        }
        Log.d("areWeSatisfied", result ? "true" : "false");
        return result;
    }

    public int getFilledCount() {
        int result = 0;

        if ((references != null) && (references.size() == 10)) { // FIXME hardcoding to 9 refs (+1 ignored) obviously sucks balls
            String medium = storyPathReference.getReferencedValue(references.get(0));
            if (medium != null) {
                // FIXME this is super fragile, assume the clip type is based on order.  ug.
                if (medium.equals("video")) {
                    result += (g(references.get(1)) ? 1 : 0);
                    result += (g(references.get(2)) ? 1 : 0);
                    result += (g(references.get(3)) ? 1 : 0);
                } else if (medium.equals("audio")) {
                    result += (g(references.get(4)) ? 1 : 0);
                    result += (g(references.get(5)) ? 1 : 0);
                    result += (g(references.get(6)) ? 1 : 0);
                } else if (medium.equals("photo")) {
                    result += (g(references.get(7)) ? 1 : 0);
                    result += (g(references.get(8)) ? 1 : 0);
                    result += (g(references.get(9)) ? 1 : 0);
                }
            }

        }
        Log.d("filledCardCount", "" + result);
        return result;
    }
}
@@ -1108,16 +1108,17 @@
 lean val
+1
  = g(ref
@@ -1134,24 +1134,25 @@
 et(0));%0A
+%0A
         
 return v
@@ -1147,18 +1147,248 @@
     
-return val
+String sv = storyPathReference.getReferencedValue(references.get(10));%0A        Log.d(%22ProgressCardModel%22, %22ref: %22 + references.get(10) + %22, val: %22 + sv);%0A        boolean val2 = (sv != null) && sv.equals(%22true%22);%0A%0A        return val1 && val2
 ;%0A  
@@ -1514,33 +1514,33 @@
 nces.size() == 1
-0
+1
 )) %7B // FIXME ha
@@ -1561,32 +1561,64 @@
 refs (+1 ignored
+ for medium) (+1 for got it card
 ) obviously suck
@@ -2827,17 +2827,17 @@
 e() == 1
-0
+1
 )) %7B // 
@@ -2874,17 +2874,50 @@
  ignored
-)
+ for medium) (+1 for got it card) 
  obvious

fix progress card's horrid refrerences hack