package com.github.tomakehurst.wiremock.admin.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.tomakehurst.wiremock.extension.Parameters;
import com.github.tomakehurst.wiremock.matching.MultiValuePattern;

import java.util.List;
import java.util.Map;

/**
 * Encapsulates options for generating and outputting StubMappings
 */
public class SnapshotSpec {
    // Whitelist requests to generate StubMappings for
    private ServeEventRequestFilters filters;
    // Headers from the request to include in the stub mapping, if they match the corresponding matcher
    private RequestPatternTransformer captureHeaders;
    // Criteria for extracting body from responses
    private ResponseDefinitionBodyMatcher extractBodyCriteria;
    // How to format StubMappings in the response body
    // Either "full" (meaning return an array of rendered StubMappings) or "ids", which returns an array of UUIDs
    private SnapshotOutputFormat outputFormat;
    // Whether to persist stub mappings
    private boolean persist = true;
    // Whether duplicate requests should be recorded as scenarios or just discarded
    private boolean repeatsAsScenarios = false;
    // Stub mapping transformers
    private List<String> transformers;
    // Parameters for stub mapping transformers
    private Parameters transformerParameters;

    @JsonCreator
    public SnapshotSpec(
        @JsonProperty("filters") ServeEventRequestFilters filters ,
        @JsonProperty("captureHeaders") Map<String, MultiValuePattern> captureHeaders,
        @JsonProperty("extractBodyCriteria") ResponseDefinitionBodyMatcher extractBodyCriteria,
        @JsonProperty("outputFormat") SnapshotOutputFormat outputFormat,
        @JsonProperty("persist") JsonNode persistNode,
        @JsonProperty("repeatsAsScenarios") JsonNode repeatsNode,
        @JsonProperty("transformers") List<String> transformers,
        @JsonProperty("transformerParameters") Parameters transformerParameters
    ) {
        this.filters = filters;
        this.outputFormat = outputFormat == null ? SnapshotOutputFormat.FULL : outputFormat;
        this.captureHeaders = new RequestPatternTransformer(captureHeaders);
        this.extractBodyCriteria = extractBodyCriteria;
        this.persist = persistNode.asBoolean(true);
        this.repeatsAsScenarios = repeatsNode.asBoolean(false);
        this.transformers = transformers;
        this.transformerParameters = transformerParameters;
    }

    public SnapshotSpec() {}

    public ServeEventRequestFilters getFilters() { return filters; }

    public RequestPatternTransformer getCaptureHeaders() { return captureHeaders; }

    public SnapshotOutputFormat getOutputFormat() { return outputFormat; }

    public boolean shouldPersist() { return persist; }

    public boolean shouldRecordRepeatsAsScenarios() { return repeatsAsScenarios; }

    public List<String> getTransformers() { return transformers; }

    public Parameters getTransformerParameters() { return transformerParameters; }

    public ResponseDefinitionBodyMatcher getExtractBodyCriteria() { return extractBodyCriteria; }
}

@@ -158,56 +158,8 @@
 ty;%0A
-import com.fasterxml.jackson.databind.JsonNode;%0A
 impo
@@ -499,16 +499,22 @@
 private 
+final 
 ServeEve
@@ -655,16 +655,22 @@
 private 
+final 
 RequestP
@@ -766,16 +766,22 @@
 private 
+final 
 Response
@@ -1004,16 +1004,22 @@
 private 
+final 
 Snapshot
@@ -1093,25 +1093,31 @@
     private 
-b
+final B
 oolean persi
@@ -1122,15 +1122,8 @@
 sist
- = true
 ;%0A  
@@ -1216,17 +1216,23 @@
 private 
-b
+final B
 oolean r
@@ -1252,16 +1252,8 @@
 rios
- = false
 ;%0A  
@@ -1295,16 +1295,22 @@
 private 
+final 
 List%3CStr
@@ -1388,16 +1388,22 @@
 private 
+final 
 Paramete
@@ -1832,24 +1832,23 @@
 t%22) 
-JsonNode
+Boolean
  persist
 Node
@@ -1843,20 +1843,16 @@
  persist
-Node
 ,%0A      
@@ -1893,28 +1893,34 @@
 s%22) 
-JsonNode repeatsNode
+Boolean repeatsAsScenarios
 ,%0A  
@@ -2106,101 +2106,8 @@
 rs;%0A
-        this.outputFormat = outputFormat == null ? SnapshotOutputFormat.FULL : outputFormat;%0A
     
@@ -2252,109 +2252,234 @@
 his.
-persist = persistNode.asBoolean(true);%0A        this.repeatsAsScenarios = repeatsNode.asBoolean(false)
+outputFormat = outputFormat == null ? SnapshotOutputFormat.FULL : outputFormat;%0A        this.persist = persist == null ? true : persist;%0A        this.repeatsAsScenarios = repeatsAsScenarios == null ? false : repeatsAsScenarios
 ;%0A  
@@ -2612,16 +2612,83 @@
 Spec() %7B
+%0A        this(null, null, null, null, null, null, null, null);%0A    
 %7D%0A%0A    p

Make all parameters final in Snapshotspec and switch JsonNode arguments to Boolean