package org.zalando.logbook;

import org.apiguardian.api.API;

import java.util.function.Predicate;

import static org.apiguardian.api.API.Status.MAINTAINED;
import static org.apiguardian.api.API.Status.STABLE;
import static org.zalando.logbook.Conditions.contentType;

@API(status = STABLE)
public final class BodyReplacers {

    private BodyReplacers() {

    }

    @API(status = MAINTAINED)
    public static <T extends HttpMessage> BodyReplacer<T> defaultValue() {
        return BodyReplacer.composite(binary(), multipart(), stream());
    }

    @API(status = MAINTAINED)
    public static <T extends HttpMessage> BodyReplacer<T> binary() {
        final Predicate<T> contentTypes = contentType(
                "application/octet-stream", "application/pdf", "audio/*", "image/*", "video/*");
        return replaceBody(contentTypes, "<binary>");
    }

    @API(status = MAINTAINED)
    public static <T extends HttpMessage> BodyReplacer<T> multipart() {
        return replaceBody(contentType("multipart/*"), "<multipart>");
    }

    @API(status = MAINTAINED)
    public static <T extends HttpMessage> BodyReplacer<T> stream() {
        final Predicate<T> contentTypes = contentType(
                "application/json-seq", // https://tools.ietf.org/html/rfc7464
                "application/x-json-stream", // https://en.wikipedia.org/wiki/JSON_Streaming#Line_delimited_JSON
                "application/stream+json", // https://tools.ietf.org/html/draft-snell-activity-streams-type-01
                "text/event-stream" // https://tools.ietf.org/html/rfc6202
        );
        return replaceBody(contentTypes, "<stream>");
    }

    public static <T extends HttpMessage> BodyReplacer<T> replaceBody(final Predicate<T> predicate,
            final String replacement) {
        return message -> predicate.test(message) ? replacement : null;
    }

}

@@ -740,16 +740,32 @@
 stream%22,
+%0A               
  %22applic
@@ -780,39 +780,716 @@
 f%22, 
-%22audio/*%22, %22image/*%22, %22video/*%22
+// Adobe Portable Document Format (PDF)%0A                %22application/vnd.ms-excel%22, // Microsoft Excel%0A                %22application/vnd.openxmlformats-officedocument.spreadsheetml.sheet%22, // Microsoft Excel (OpenXML)%0A                %22application/msword%22, // Microsoft Word%0A                %22application/vnd.openxmlformats-officedocument.wordprocessingml.document%22, // Microsoft Word (OpenXML)%0A                %22application/vnd.ms-powerpoint%22, // Microsoft PowerPoint%0A                %22application/vnd.openxmlformats-officedocument.presentationml.presentation%22, // Microsoft PowerPoint (OpenXML)%0A                %22audio/*%22, // Audio%0A                %22image/*%22, // Image%0A                %22video/*%22  // Video%0A        
 );%0A 
@@ -2220,16 +2220,17 @@
 -stream%22
+,
  // http
@@ -2261,16 +2261,77 @@
 rfc6202%0A
+                %22application/x-ndjson%22 // https://ndjson.org%0A
         

add microsoft vendor-specific content types to be excluded by default (#1213)