package org.commcare.utils;

import org.commcare.android.database.user.models.FormRecord;
import org.commcare.views.notifications.MessageTag;
import org.commcare.views.notifications.NotificationMessage;
import org.commcare.views.notifications.NotificationMessageFactory;
import org.commcare.views.notifications.ProcessIssues;
import org.javarosa.core.services.locale.Localization;

/**
 * Created by amstone326 on 9/25/17.
 */

public class QuarantineUtil {

    public static String getQuarantineReasonDisplayString(FormRecord r, boolean includeDetail) {
        StringBuilder builder = new StringBuilder();
        switch (r.getQuarantineReasonType()) {
            case FormRecord.QuarantineReason_LOCAL_PROCESSING_ERROR:
                builder.append(Localization.get("quarantine.reason.local.processing"));
                break;
            case FormRecord.QuarantineReason_SERVER_PROCESSING_ERROR:
                builder.append(Localization.get("quarantine.reason.server.processing"));
                break;
            case FormRecord.QuarantineReason_RECORD_ERROR:
                builder.append(Localization.get("quarantine.reason.record.error"));
                break;
            case FormRecord.QuarantineReason_MANUAL:
                builder.append(Localization.get("quarantine.reason.manual"));
                break;
            case FormRecord.QuarantineReason_FILE_NOT_FOUND:
                builder.append(Localization.get("quarantine.reason.fnf"));
                break;
            default:
                builder.append(Localization.get("quarantine.reason.unknown"));
        }

        if (includeDetail) {
            String detail = r.getQuarantineReasonDetail();
            if (detail != null) {
                builder.append(": " + detail);
            }
        }

        return builder.toString();
    }

    public static NotificationMessage getQuarantineNotificationMessage(FormRecord r) {
        MessageTag tag;
        switch (r.getQuarantineReasonType()) {
            case FormRecord.QuarantineReason_LOCAL_PROCESSING_ERROR:
                tag = ProcessIssues.RecordQuarantinedLocalProcessingIssue;
                break;
            case FormRecord.QuarantineReason_SERVER_PROCESSING_ERROR:
                tag = ProcessIssues.RecordQuarantinedServerIssue;
                break;
            case FormRecord.QuarantineReason_RECORD_ERROR:
                tag = ProcessIssues.RecordQuarantinedRecordIssue;
                break;
            case FormRecord.QuarantineReason_FILE_NOT_FOUND:
                tag = ProcessIssues.RecordFilesMissing;
                break;
            case FormRecord.QuarantineReason_MANUAL:
            default:
                return null;
        }
        return NotificationMessageFactory.message(tag);
    }
}

@@ -567,45 +567,27 @@
 ring
-Builder builder = new StringBuilder()
+ displayString = %22%22
 ;%0A  
@@ -712,39 +712,41 @@
             
-builder.append(
+displayString += 
 Localization
@@ -779,33 +779,32 @@
 cal.processing%22)
-)
 ;%0A              
@@ -894,39 +894,41 @@
             
-builder.append(
+displayString += 
 Localization
@@ -970,17 +970,16 @@
 essing%22)
-)
 ;%0A      
@@ -1066,39 +1066,41 @@
             
-builder.append(
+displayString += 
 Localization
@@ -1137,17 +1137,16 @@
 .error%22)
-)
 ;%0A      
@@ -1227,39 +1227,41 @@
             
-builder.append(
+displayString += 
 Localization
@@ -1292,17 +1292,16 @@
 manual%22)
-)
 ;%0A      
@@ -1390,39 +1390,41 @@
             
-builder.append(
+displayString += 
 Localization
@@ -1452,17 +1452,16 @@
 on.fnf%22)
-)
 ;%0A      
@@ -1514,31 +1514,33 @@
         
-builder.append(
+displayString += 
 Localiza
@@ -1576,17 +1576,16 @@
 nknown%22)
-)
 ;%0A      
@@ -1731,22 +1731,25 @@
     
-builder.append
+displayString += 
 (%22: 
@@ -1805,26 +1805,21 @@
 urn 
-builder.to
+display
 String
-()
 ;%0A  

Revert "use string builder"