package colector.co.com.collector.model.request;

import android.content.Context;

import java.util.ArrayList;
import java.util.List;

import colector.co.com.collector.ColectorApplication;
import colector.co.com.collector.R;
import colector.co.com.collector.model.IdInputValue;
import colector.co.com.collector.model.IdValue;
import colector.co.com.collector.model.Survey;
import colector.co.com.collector.session.AppSession;
import colector.co.com.collector.utils.NetworkUtils;

/**
 * Created by dherrera on 11/10/15.
 */
public class SendSurveyRequest {

    private String colector_id;
    private String form_id;
    private String longitud;
    private String latitud;
    private String horaini;
    private String horafin;
    private List<IdInputValue> responses;


    public SendSurveyRequest(Survey survey) {
        this.colector_id = String.valueOf(AppSession.getInstance().getUser().getColector_id());
        this.form_id = String.valueOf(survey.getForm_id());
        this.longitud = survey.getInstanceLongitude();
        this.latitud = survey.getInstanceLatitude();
        this.horaini = survey.getInstanceHoraIni();
        this.horafin = survey.getInstanceHoraFin();
        this.setResponsesData(survey.getInstanceAnswers());
    }

    public List<IdInputValue> getResponses() {
        return responses;
    }

    public void setResponses(List<IdInputValue> responses) {
        this.responses = responses;
    }

    private void setResponsesData(List<IdValue> responsesData) {
        responses = new ArrayList<>();
        for (IdValue item : responsesData) {
            if (item.getmType() != 6)
                responses.add(new IdInputValue(String.valueOf(item.getId()), item.getValue()));
            else {
                int lastIndex = item.getValue().length();
                int slashIndex = item.getValue().lastIndexOf("/");
                responses.add(new IdInputValue(String.valueOf(item.getId()), ColectorApplication.getInstance().getString(R.string.image_name_format,
                        NetworkUtils.getAndroidID(ColectorApplication.getInstance()),
                        item.getValue().substring((slashIndex + 1), lastIndex))));
            }

        }
    }
}


@@ -47,41 +47,8 @@
 t;%0A%0A
-import android.content.Context;%0A%0A
 impo
@@ -1565,10 +1565,14 @@
     
-if
+switch
  (it
@@ -1588,14 +1588,11 @@
 pe()
- != 6)
+) %7B
 %0A   
@@ -1608,88 +1608,20 @@
     
-responses.add(new IdInputValue(String.valueOf(item.getId()), item.getValue()));%0A
+case 6:%0A    
     
@@ -1632,14 +1632,16 @@
     
-else %7B
+case 14:
 %0A   
@@ -1649,24 +1649,28 @@
             
+    
 int lastInde
@@ -1695,24 +1695,28 @@
 ).length();%0A
+    
             
@@ -1778,32 +1778,36 @@
                 
+    
 responses.add(ne
@@ -1947,16 +1947,20 @@
         
+    
 NetworkU
@@ -2037,16 +2037,20 @@
         
+    
 item.get
@@ -2096,24 +2096,176 @@
 tIndex))));%0A
+                    break;%0A                default:%0A                    responses.add(new IdInputValue(String.valueOf(item.getId()), item.getValue()));%0A
             

Add image type of response on SendSurveyRequest considering signature type of layout