// 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
// 
// }


import uk.co.visalia.brightpearl.apiclient.ServiceName;
import uk.co.visalia.brightpearl.apiclient.http.Method;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Map;
/*
 * 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;



/**
 * <p>
 * This is the superclass for read and write request classes, providing the functionality common to both. It is only
 * intended for use internally so has a package private constructor.
 * </p><p>
 * Requests are split into read requests (including searches) and write requests because write requests can be included
 * in multimessages and read requests cannot, and because read requests can be cached and write requests cannot.
 * </p>
 * @param <T> A placeholder for the type expected in the response, avoiding the requirement to cast 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 abstract class AbstractServiceRequest<T> {

    private final String ruid;

    private final ServiceName service;

    private final Method method;

    private final String path;

    private final Type responseType;

    private final Map<String, String> params;

// 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/request/AbstractServiceRequest.java
import uk.co.visalia.brightpearl.apiclient.ServiceName;
import uk.co.visalia.brightpearl.apiclient.http.Method;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Map;

/*
 * 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;



/**
 * <p>
 * This is the superclass for read and write request classes, providing the functionality common to both. It is only
 * intended for use internally so has a package private constructor.
 * </p><p>
 * Requests are split into read requests (including searches) and write requests because write requests can be included
 * in multimessages and read requests cannot, and because read requests can be cached and write requests cannot.
 * </p>
 * @param <T> A placeholder for the type expected in the response, avoiding the requirement to cast 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 abstract class AbstractServiceRequest<T> {

    private final String ruid;

    private final ServiceName service;

    private final Method method;

    private final String path;

    private final Type responseType;

    private final Map<String, String> params;

    AbstractServiceRequest(String ruid, ServiceName service, Method method, String path, Type responseType, Map<String, String> params) {