package org.silverpeas.mobile.shared.services.rest;

import static org.fusesource.restygwt.client.AbstractJsonEncoderDecoder.*;

public class ServiceContact_Generated_RestServiceProxy_ implements org.silverpeas.mobile.shared.services.rest.ServiceContact, org.fusesource.restygwt.client.RestServiceProxy {
  private org.fusesource.restygwt.client.Resource resource = null;
  
  public void setResource(org.fusesource.restygwt.client.Resource resource) {
    this.resource = resource;
  }
  public org.fusesource.restygwt.client.Resource getResource() {
    if (this.resource == null) {
      String serviceRoot = org.fusesource.restygwt.client.Defaults.getServiceRoot();
      this.resource = new org.fusesource.restygwt.client.Resource(serviceRoot).resolve("/mobile/contact");
    }
    return this.resource;
  }
  private org.fusesource.restygwt.client.Dispatcher dispatcher = null;
  
  public void setDispatcher(org.fusesource.restygwt.client.Dispatcher dispatcher) {
    this.dispatcher = dispatcher;
  }
  
  public org.fusesource.restygwt.client.Dispatcher getDispatcher() {
    return this.dispatcher;
  }
  public void getContacts(java.lang.String type, java.lang.String filter, int pageSize, int startIndex, org.fusesource.restygwt.client.MethodCallback<java.util.List<org.silverpeas.mobile.shared.dto.DetailUserDTO>> callback) {
    final java.lang.String final_type = type;
    final java.lang.String final_filter = filter;
    final int final_pageSize = pageSize;
    final int final_startIndex = startIndex;
    final org.fusesource.restygwt.client.Method __method =
    getResource()
    .resolve("paging/"+(type== null? null : com.google.gwt.http.client.URL.encodePathSegment(type))+"/")
    .addQueryParam("filter", filter)
    .addQueryParam("startIndex", ""+startIndex)
    .addQueryParam("pageSize", ""+pageSize)
    .get();
    __method.setDispatcher(this.dispatcher);
    __method.header(org.fusesource.restygwt.client.Resource.HEADER_ACCEPT, "application/json");
    try {
      __method.send(new org.fusesource.restygwt.client.AbstractRequestCallback<java.util.List<org.silverpeas.mobile.shared.dto.DetailUserDTO>>(__method, callback) {
        protected java.util.List<org.silverpeas.mobile.shared.dto.DetailUserDTO> parseResult() throws Exception {
          try {
            return toList(com.google.gwt.json.client.JSONParser.parse(__method.getResponse().getText()), org.silverpeas.mobile.shared.dto.DetailUserDTO_Generated_JsonEncoderDecoder_.INSTANCE);
          } catch (Throwable __e) {
            throw new org.fusesource.restygwt.client.ResponseFormatException("Response was NOT a valid JSON document", __e);
          }
        }
      });
    } catch (com.google.gwt.http.client.RequestException __e) {
      callback.onFailure(__method,__e);
    }
  }
  public void getContactsFiltered(java.lang.String type, java.lang.String filter, org.fusesource.restygwt.client.MethodCallback<java.util.List<org.silverpeas.mobile.shared.dto.DetailUserDTO>> callback) {
    final java.lang.String final_type = type;
    final java.lang.String final_filter = filter;
    final org.fusesource.restygwt.client.Method __method =
    getResource()
    .resolve(""+(type== null? null : com.google.gwt.http.client.URL.encodePathSegment(type))+"/")
    .addQueryParam("filter", filter)
    .get();
    __method.setDispatcher(this.dispatcher);
    __method.header(org.fusesource.restygwt.client.Resource.HEADER_ACCEPT, "application/json");
    try {
      __method.send(new org.fusesource.restygwt.client.AbstractRequestCallback<java.util.List<org.silverpeas.mobile.shared.dto.DetailUserDTO>>(__method, callback) {
        protected java.util.List<org.silverpeas.mobile.shared.dto.DetailUserDTO> parseResult() throws Exception {
          try {
            return toList(com.google.gwt.json.client.JSONParser.parse(__method.getResponse().getText()), org.silverpeas.mobile.shared.dto.DetailUserDTO_Generated_JsonEncoderDecoder_.INSTANCE);
          } catch (Throwable __e) {
            throw new org.fusesource.restygwt.client.ResponseFormatException("Response was NOT a valid JSON document", __e);
          }
        }
      });
    } catch (com.google.gwt.http.client.RequestException __e) {
      callback.onFailure(__method,__e);
    }
  }
  public void hasContacts(org.fusesource.restygwt.client.MethodCallback<org.silverpeas.mobile.shared.dto.contact.ContactFilters> callback) {
    final org.fusesource.restygwt.client.Method __method =
    getResource()
    .resolve("hasContacts/")
    .get();
    __method.setDispatcher(this.dispatcher);
    __method.header(org.fusesource.restygwt.client.Resource.HEADER_ACCEPT, "application/json");
    try {
      __method.send(new org.fusesource.restygwt.client.AbstractRequestCallback<org.silverpeas.mobile.shared.dto.contact.ContactFilters>(__method, callback) {
        protected org.silverpeas.mobile.shared.dto.contact.ContactFilters parseResult() throws Exception {
          try {
            return org.silverpeas.mobile.shared.dto.contact.ContactFilters_Generated_JsonEncoderDecoder_.INSTANCE.decode(com.google.gwt.json.client.JSONParser.parse(__method.getResponse().getText()));
          } catch (Throwable __e) {
            throw new org.fusesource.restygwt.client.ResponseFormatException("Response was NOT a valid JSON document", __e);
          }
        }
      });
    } catch (com.google.gwt.http.client.RequestException __e) {
      callback.onFailure(__method,__e);
    }
  }
}
