package org.oskari.wcs.request;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.oskari.wcs.capabilities.Capabilities;
import org.oskari.wcs.capabilities.Operation;
import org.oskari.wcs.util.Maps;

public class DescribeCoverage {

    private DescribeCoverage() { /* Block */ }

    /**
     * Create query parameters for a GET encoded DescribeCoverage request You
     * can use {@link #coverageExists(Capabilities, String)} to see if the
     * coverage exists
     *
     * @param coverageId
     *            id of the coverage
     * @return Map with query parameters
     */
    public static Map<String, String> toQueryParameters(String coverageId) {
        return Maps.of(
                "service", "WCS",
                "version", "2.0.1",
                "request", "DescribeCoverage",
                "coverageId", coverageId);
    }

    /**
     * Get the HTTP endpoint declared in GetCapabilities for DescribeCoverage
     * request
     *
     * @param wcs capabilities of the service
     * @param get true if you want the GET endpoint, false if POST
     * @return the endpoint which might not exist for your binding
     */
    public static Optional<String> getDescribeCoverageEndPoint(Capabilities wcs, boolean get) {
        Objects.requireNonNull(wcs);
        if (get) {
            if (!wcs.supportsGET()) {
                return Optional.empty();
            }
        } else {
            if (!wcs.supportsPOST()) {
                return Optional.empty();
            }
        }
        Operation op = wcs.findOperation("DescribeCoverage")
                .orElseThrow(() -> new IllegalArgumentException(
                        "The OperationsMetadata component shall contain three "
                                + "Operation instances with case-sensitive name values "
                                + "'GetCapabilities', 'DescribeCoverage', and “GetCoverage'"));
        return get ? op.getGet() : op.getPost();
    }

}

@@ -949,16 +949,35 @@
 ties for
+%0A     * GET encoded
  Describ
@@ -985,23 +985,16 @@
 Coverage
-%0A     *
  request
@@ -1051,75 +1051,8 @@
 ice%0A
-     * @param get true if you want the GET endpoint, false if POST%0A
     
@@ -1105,12 +1105,11 @@
 for 
-your
+GET
  bin
@@ -1183,16 +1183,19 @@
 EndPoint
+GET
 (Capabil
@@ -1207,21 +1207,8 @@
  wcs
-, boolean get
 ) %7B%0A
@@ -1260,129 +1260,869 @@
 if (
-get) %7B%0A            if (!wcs.supportsGET()) %7B%0A                return Optional.empty();%0A        
+!wcs.supportsGET()) %7B%0A            return Optional.empty();%0A        %7D%0A        Operation op = wcs.findOperation(%22DescribeCoverage%22)%0A                .orElseThrow(() -%3E new IllegalArgumentException(%0A                        %22The OperationsMetadata component shall contain three %22%0A                                + %22Operation instances with case-sensitive name values %22%0A                                + %22'GetCapabilities', 'DescribeCoverage', and 'GetCoverage'%22));%0A        return op.getGet();%0A
     %7D%0A
+%0A
     
-    %7D else %7B%0A    
+/**%0A     * Get the HTTP endpoint declared in GetCapabilities for%0A     * POST encoded DescribeCoverage request%0A     *%0A     * @param wcs capabilities of the service%0A     * @return the endpoint which might not exist for POST binding%0A     */%0A    public static Optional%3CString%3E getDescribeCoverageEndPointPOST(Capabilities wcs) %7B%0A        Objects.requireNonNull(wcs);%0A
     
@@ -2156,36 +2156,32 @@
 ) %7B%0A            
-    
 return Optional.
@@ -2193,22 +2193,8 @@
 ();%0A
-            %7D%0A
     
@@ -2576,9 +2576,9 @@
 and 
-%E2%80%9C
+'
 GetC
@@ -2608,28 +2608,8 @@
 turn
- get ? op.getGet() :
  op.

Split DescribeCoverage.getDescribeCoverageEndPoint to two functions, one for each binding (GET and POST)