// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/ServiceName.java
// public final class ServiceName {
// 
//     private static final Pattern PATH_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-]+");
// 
//     public static final ServiceName ACCOUNTING = new ServiceName("accounting-service");
//     public static final ServiceName CONTACT = new ServiceName("contact-service");
//     public static final ServiceName INTEGRATION = new ServiceName("integration-service");
//     public static final ServiceName ORDER = new ServiceName("order-service");
//     public static final ServiceName PRODUCT = new ServiceName("product-service");
//     public static final ServiceName WAREHOUSE = new ServiceName("warehouse-service");
// 
//     private final String path;
// 
//     /**
//      * Constructs a custom service name instance, using the path, for example &quot;product-service&quot;.
//      * @param path path component for the service.
//      */
//     public ServiceName(String path) {
//         validatePath(path);
//         this.path = path;
//     }
// 
//     /**
//      * Returns the URI component for the service, for example &quot;product-service&quot;.
//      * @return path component for the service.
//      */
//     public String getPath() {
//         return path;
//     }
// 
//     private void validatePath(String path) {
//         if (path == null || path.trim().length() == 0) {
//             throw new IllegalArgumentException("Service path must be provided");
//         } else if (!PATH_PATTERN.matcher(path).matches()) {
//             throw new IllegalArgumentException("Service must contain alphanumeric characters, hyphen and underscore only");
//         }
//     }
// 
//     @Override
//     public String toString() {
//         return "ServiceName{" +
//                 "path='" + path + '\'' +
//                 '}';
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
//         ServiceName that = (ServiceName) o;
//         if (path != null ? !path.equals(that.path) : that.path != null) return false;
//         return true;
//     }
// 
//     @Override
//     public int hashCode() {
//         return path != null ? path.hashCode() : 0;
//     }
// }
// 
// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/http/Method.java
// public enum Method {
// 
//     GET,
//     POST,
//     PUT,
//     DELETE,
//     OPTIONS
// 
// }
// 
// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/util/StringUtils.java
// public final class StringUtils {
// 
//     private StringUtils() { }
// 
//     public static boolean isEmpty(String string) {
//         return string == null || string.length() == 0;
//     }
// 
//     public static boolean isNotEmpty(String string) {
//         return !isEmpty(string);
//     }
// 
//     public static boolean isBlank(String string) {
//         return string == null || string.trim().length() == 0;
//     }
// 
//     public static boolean isNotBlank(String string) {
//         return !isBlank(string);
//     }
// 
//     public static boolean equals(String lhs, String rhs) {
//         if ((lhs == null) != (rhs == null)) {
//             return false;
//         } else if (lhs == null && rhs == null) {
//             return true;
//         } else {
//             return lhs.equals(rhs);
//         }
//     }
// 
//     public static String join(Collection<String> strings, String separator) {
//         StringBuilder builder = new StringBuilder();
//         for (String string : strings) {
//             if (builder.length() > 0) {
//                 builder.append(separator);
//             }
//             builder.append(string);
//         }
//         return builder.toString();
//     }
// 
// }


import uk.co.visalia.brightpearl.apiclient.ServiceName;
import uk.co.visalia.brightpearl.apiclient.http.Method;
import uk.co.visalia.brightpearl.apiclient.util.StringUtils;
import java.lang.reflect.Type;
import java.util.UUID;
/*
 * Copyright 2014 David Morrissey
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.co.visalia.brightpearl.apiclient.request;



/**
 * A factory for immutable {@link ServiceWriteRequest} instances. Static methods provide POST, PUT and DELETE requests configured
 * with the minimum fields needed to execute a request, and chaining methods are available to set additional attributes
 * on the request before an immutable instance is build with {@link #build()}.
 * @param <T> placeholder for the response type, used to avoid casting of responses. This is not
 *           linked to the {@link Type} set on a request so a {@link ClassCastException} is possible if the type is set
 *           incorrectly.
 */
public class ServiceWriteRequestBuilder<T> extends AbstractServiceRequestBuilder<ServiceWriteRequestBuilder<T>> {

    private ServiceWriteRequestBuilder() {
        super();
    }

    private Object entity;

    @Override
    protected ServiceWriteRequestBuilder<T> getThis() {
        return this;
    }

    /**
     * Creates a new POST request builder configured with the URL to call and expected response type. This method does
     * not support extraction of generic types but is able to infer the type parameter &lt;T&gt;.
     * @param service Brightpearl service that contains the resource.
     * @param path path to the search resource, for example '/product'.
     * @param entity an object to be serialised as JSON and included in the request body. Null is permitted, but rarely appropriate.
     * @param responseType type of result expected in the 'response' element of the JSON response body. Use Void or null if no response is expected, or the response is not required.
     * @param <T> placeholder for the response type, used to avoid casting of responses.
     * @return A POST request builder instance.
     */
    public static <T> ServiceWriteRequestBuilder<T> newPostRequest(ServiceName service, String path, Object entity, Class<T> responseType) {
        ServiceWriteRequestBuilder<T> builder = new ServiceWriteRequestBuilder<T>();
// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/ServiceName.java
// public final class ServiceName {
// 
//     private static final Pattern PATH_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-]+");
// 
//     public static final ServiceName ACCOUNTING = new ServiceName("accounting-service");
//     public static final ServiceName CONTACT = new ServiceName("contact-service");
//     public static final ServiceName INTEGRATION = new ServiceName("integration-service");
//     public static final ServiceName ORDER = new ServiceName("order-service");
//     public static final ServiceName PRODUCT = new ServiceName("product-service");
//     public static final ServiceName WAREHOUSE = new ServiceName("warehouse-service");
// 
//     private final String path;
// 
//     /**
//      * Constructs a custom service name instance, using the path, for example &quot;product-service&quot;.
//      * @param path path component for the service.
//      */
//     public ServiceName(String path) {
//         validatePath(path);
//         this.path = path;
//     }
// 
//     /**
//      * Returns the URI component for the service, for example &quot;product-service&quot;.
//      * @return path component for the service.
//      */
//     public String getPath() {
//         return path;
//     }
// 
//     private void validatePath(String path) {
//         if (path == null || path.trim().length() == 0) {
//             throw new IllegalArgumentException("Service path must be provided");
//         } else if (!PATH_PATTERN.matcher(path).matches()) {
//             throw new IllegalArgumentException("Service must contain alphanumeric characters, hyphen and underscore only");
//         }
//     }
// 
//     @Override
//     public String toString() {
//         return "ServiceName{" +
//                 "path='" + path + '\'' +
//                 '}';
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
//         ServiceName that = (ServiceName) o;
//         if (path != null ? !path.equals(that.path) : that.path != null) return false;
//         return true;
//     }
// 
//     @Override
//     public int hashCode() {
//         return path != null ? path.hashCode() : 0;
//     }
// }
// 
// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/http/Method.java
// public enum Method {
// 
//     GET,
//     POST,
//     PUT,
//     DELETE,
//     OPTIONS
// 
// }
// 
// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/util/StringUtils.java
// public final class StringUtils {
// 
//     private StringUtils() { }
// 
//     public static boolean isEmpty(String string) {
//         return string == null || string.length() == 0;
//     }
// 
//     public static boolean isNotEmpty(String string) {
//         return !isEmpty(string);
//     }
// 
//     public static boolean isBlank(String string) {
//         return string == null || string.trim().length() == 0;
//     }
// 
//     public static boolean isNotBlank(String string) {
//         return !isBlank(string);
//     }
// 
//     public static boolean equals(String lhs, String rhs) {
//         if ((lhs == null) != (rhs == null)) {
//             return false;
//         } else if (lhs == null && rhs == null) {
//             return true;
//         } else {
//             return lhs.equals(rhs);
//         }
//     }
// 
//     public static String join(Collection<String> strings, String separator) {
//         StringBuilder builder = new StringBuilder();
//         for (String string : strings) {
//             if (builder.length() > 0) {
//                 builder.append(separator);
//             }
//             builder.append(string);
//         }
//         return builder.toString();
//     }
// 
// }


// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/request/ServiceWriteRequestBuilder.java
import uk.co.visalia.brightpearl.apiclient.ServiceName;
import uk.co.visalia.brightpearl.apiclient.http.Method;
import uk.co.visalia.brightpearl.apiclient.util.StringUtils;
import java.lang.reflect.Type;
import java.util.UUID;

/*
 * Copyright 2014 David Morrissey
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package uk.co.visalia.brightpearl.apiclient.request;



/**
 * A factory for immutable {@link ServiceWriteRequest} instances. Static methods provide POST, PUT and DELETE requests configured
 * with the minimum fields needed to execute a request, and chaining methods are available to set additional attributes
 * on the request before an immutable instance is build with {@link #build()}.
 * @param <T> placeholder for the response type, used to avoid casting of responses. This is not
 *           linked to the {@link Type} set on a request so a {@link ClassCastException} is possible if the type is set
 *           incorrectly.
 */
public class ServiceWriteRequestBuilder<T> extends AbstractServiceRequestBuilder<ServiceWriteRequestBuilder<T>> {

    private ServiceWriteRequestBuilder() {
        super();
    }

    private Object entity;

    @Override
    protected ServiceWriteRequestBuilder<T> getThis() {
        return this;
    }

    /**
     * Creates a new POST request builder configured with the URL to call and expected response type. This method does
     * not support extraction of generic types but is able to infer the type parameter &lt;T&gt;.
     * @param service Brightpearl service that contains the resource.
     * @param path path to the search resource, for example '/product'.
     * @param entity an object to be serialised as JSON and included in the request body. Null is permitted, but rarely appropriate.
     * @param responseType type of result expected in the 'response' element of the JSON response body. Use Void or null if no response is expected, or the response is not required.
     * @param <T> placeholder for the response type, used to avoid casting of responses.
     * @return A POST request builder instance.
     */
    public static <T> ServiceWriteRequestBuilder<T> newPostRequest(ServiceName service, String path, Object entity, Class<T> responseType) {
        ServiceWriteRequestBuilder<T> builder = new ServiceWriteRequestBuilder<T>();
        return builder.withMethod(Method.POST)