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) {
        String displayString = "";
        switch (r.getQuarantineReasonType()) {
            case FormRecord.QuarantineReason_LOCAL_PROCESSING_ERROR:
                displayString += Localization.get("quarantine.reason.local.processing");
                break;
            case FormRecord.QuarantineReason_SERVER_PROCESSING_ERROR:
                displayString += Localization.get("quarantine.reason.server.processing");
                break;
            case FormRecord.QuarantineReason_RECORD_ERROR:
                displayString += Localization.get("quarantine.reason.record.error");
                break;
            case FormRecord.QuarantineReason_MANUAL:
                displayString += Localization.get("quarantine.reason.manual");
                break;
            case FormRecord.QuarantineReason_FILE_NOT_FOUND:
                displayString += Localization.get("quarantine.reason.fnf");
                break;
            default:
                displayString += Localization.get("quarantine.reason.unknown");
        }

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

        return displayString;
    }

    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,27 +567,45 @@
 ring
- displayString = %22%22
+Builder builder = new StringBuilder()
 ;%0A  
@@ -734,33 +734,31 @@
         
-displayString += 
+builder.append(
 Localiza
@@ -795,32 +795,33 @@
 cal.processing%22)
+)
 ;%0A              
@@ -915,33 +915,31 @@
         
-displayString += 
+builder.append(
 Localiza
@@ -985,16 +985,17 @@
 essing%22)
+)
 ;%0A      
@@ -1086,33 +1086,31 @@
         
-displayString += 
+builder.append(
 Localiza
@@ -1151,16 +1151,17 @@
 .error%22)
+)
 ;%0A      
@@ -1246,33 +1246,31 @@
         
-displayString += 
+builder.append(
 Localiza
@@ -1305,16 +1305,17 @@
 manual%22)
+)
 ;%0A      
@@ -1408,33 +1408,31 @@
         
-displayString += 
+builder.append(
 Localiza
@@ -1464,16 +1464,17 @@
 on.fnf%22)
+)
 ;%0A      
@@ -1527,33 +1527,31 @@
         
-displayString += 
+builder.append(
 Localiza
@@ -1587,16 +1587,17 @@
 nknown%22)
+)
 ;%0A      
@@ -1743,25 +1743,22 @@
     
-displayString += 
+builder.append
 (%22: 
@@ -1814,21 +1814,26 @@
 urn 
-display
+builder.to
 String
+()
 ;%0A  

use string builder