// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/request/ServiceWriteRequest.java
// public class ServiceWriteRequest<T> extends AbstractServiceRequest<T> {
// 
//     private final Object entity;
// 
//     ServiceWriteRequest(String ruid, ServiceName service, Method method, String path, Type responseType, Map<String, String> params, Object entity) {
//         super(ruid, service, method, path, responseType, params);
//         this.entity = entity;
//     }
// 
//     /**
//      * The entity to be serialised as JSON and sent as the request body.
//      * @return the request entity object.
//      */
//     public Object getEntity() {
//         return entity;
//     }
// 
// }


import uk.co.visalia.brightpearl.apiclient.request.ServiceWriteRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/*
 * 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.multimessage;



/**
 * Utilities for multimessage requests.
 */
public final class MultiMessageUtils {

    private MultiMessageUtils() { }

    /**
     * Splits a {@link MultiRequest} into as many requests as necessary to give no more than ten request, whilst also
     * avoiding batches of one request (except when the supplied request contains only one request). This is used
     * internally by {@link uk.co.visalia.brightpearl.apiclient.BrightpearlApiClient} to split requests but may also be used externally to give greater
     * control over the execution of large batches in case a multimessage or an individual request fails.
     */
    public static List<MultiRequest> split(MultiRequest multiRequest) {
        if (multiRequest.getRequests().size() > 10) {
            List<MultiRequest> requests = new ArrayList<MultiRequest>();
// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/request/ServiceWriteRequest.java
// public class ServiceWriteRequest<T> extends AbstractServiceRequest<T> {
// 
//     private final Object entity;
// 
//     ServiceWriteRequest(String ruid, ServiceName service, Method method, String path, Type responseType, Map<String, String> params, Object entity) {
//         super(ruid, service, method, path, responseType, params);
//         this.entity = entity;
//     }
// 
//     /**
//      * The entity to be serialised as JSON and sent as the request body.
//      * @return the request entity object.
//      */
//     public Object getEntity() {
//         return entity;
//     }
// 
// }


// Path: src/main/java/uk/co/visalia/brightpearl/apiclient/multimessage/MultiMessageUtils.java
import uk.co.visalia.brightpearl.apiclient.request.ServiceWriteRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

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



/**
 * Utilities for multimessage requests.
 */
public final class MultiMessageUtils {

    private MultiMessageUtils() { }

    /**
     * Splits a {@link MultiRequest} into as many requests as necessary to give no more than ten request, whilst also
     * avoiding batches of one request (except when the supplied request contains only one request). This is used
     * internally by {@link uk.co.visalia.brightpearl.apiclient.BrightpearlApiClient} to split requests but may also be used externally to give greater
     * control over the execution of large batches in case a multimessage or an individual request fails.
     */
    public static List<MultiRequest> split(MultiRequest multiRequest) {
        if (multiRequest.getRequests().size() > 10) {
            List<MultiRequest> requests = new ArrayList<MultiRequest>();
            List<ServiceWriteRequest> batch = new ArrayList<ServiceWriteRequest>();