package com.stanfy.enroscar.rest;

import com.stanfy.enroscar.beans.BeansContainer;
import com.stanfy.enroscar.beans.BeansManager;
import com.stanfy.enroscar.beans.EnroscarBean;
import com.stanfy.enroscar.beans.InitializingBean;
import com.stanfy.enroscar.beans.ManagerAwareBean;
import com.stanfy.enroscar.rest.request.RequestDescription;
import com.stanfy.enroscar.rest.response.DefaultResponseModelConverter;
import com.stanfy.enroscar.rest.response.ResponseModelConverter;

/**
 * Configures remote server API access classes.
 * @author Roman Mazur (Stanfy - http://stanfy.com)
 */
@EnroscarBean(RemoteServerApiConfiguration.BEAN_NAME)
public class RemoteServerApiConfiguration implements InitializingBean, ManagerAwareBean {

  /** Bean name. */
  public static final String BEAN_NAME = "RemoteServerApiConfiguration";

  /** Bean manager instance. */
  private BeansManager beansManager;

  /** Request method. */
  private RequestMethod requestMethod;
  /** Response model converter. */
  private ResponseModelConverter responseModelConverter;

  /** Default content handler name. */
  private String defaultContentHandlerName;

  /** Default cache bean name. */
  private String defaultCacheBeanName;

  /** Debug REST calls. */
  private boolean debugRest;
  
  /** Debug REST response. */
  private boolean debugRestResponse;

  public void setRequestMethod(final RequestMethod requestMethod) {
    this.requestMethod = requestMethod;
  }
  public void setResponseModelConverter(final ResponseModelConverter responseModelConverter) {
    this.responseModelConverter = responseModelConverter;
  }


  public RequestMethod getRequestMethod(final RequestDescription requestDescription) { return requestMethod; }
  public ResponseModelConverter getResponseModelConverter(final RequestDescription requestDescription) { return responseModelConverter; }

  public String getDefaultContentHandlerName() { return defaultContentHandlerName; }
  public void setDefaultContentHandlerName(final String defaultContentHandlerName) {
    checkBeanExists(defaultContentHandlerName);
    this.defaultContentHandlerName = defaultContentHandlerName;
  }

  public String getDefaultCacheBeanName() { return defaultCacheBeanName; }
  public void setDefaultCacheBeanName(final String defaultCacheBeanName) {
    checkBeanExists(defaultCacheBeanName);
    this.defaultCacheBeanName = defaultCacheBeanName;
  }

  public void setDebugRest(final boolean debugRest) { this.debugRest = debugRest; }
  public boolean isDebugRestResponse() { return debugRestResponse; }
  
  public void setDebugRestResponse(final boolean debugRestResponse) { this.debugRestResponse = debugRestResponse; }
  public boolean isDebugRest() { return debugRest; }
  
  /**
   * Throw {@link IllegalArgumentException} if the specified bean does not exist in the beans container.
   * @param name bean name
   */
  protected void checkBeanExists(final String name) {
    if (name == null) { throw new NullPointerException("Bean name cannot be null"); }
    if (!beansManager.getContainer().containsBean(name)) {
      throw new IllegalArgumentException("Bean " + name + " does not exist");
    }
  }

  public RequestDescription createRequestDescription() { return new RequestDescription(); }

  @Override
  public void onInitializationFinished(final BeansContainer beansContainer) {
    if (this.requestMethod == null) {
      this.requestMethod = new RequestMethod();
    }
    if (this.responseModelConverter == null) {
      this.responseModelConverter = new DefaultResponseModelConverter();
    }
  }

  @Override
  public void setBeansManager(final BeansManager beansManager) {
    this.beansManager = beansManager;
  }

}

@@ -929,33 +929,40 @@
 e RequestMethod 
-r
+defaultR
 equestMethod;%0A  
@@ -1019,33 +1019,40 @@
 eModelConverter 
-r
+defaultR
 esponseModelConv
@@ -1361,16 +1361,23 @@
 void set
+Default
 RequestM
@@ -1420,33 +1420,40 @@
 hod) %7B%0A    this.
-r
+defaultR
 equestMethod = r
@@ -1487,16 +1487,23 @@
 void set
+Default
 Response
@@ -1573,33 +1573,40 @@
 ter) %7B%0A    this.
-r
+defaultR
 esponseModelConv
@@ -1737,17 +1737,24 @@
  return 
-r
+defaultR
 equestMe
@@ -1873,17 +1873,24 @@
  return 
-r
+defaultR
 esponseM
@@ -3398,25 +3398,32 @@
    if (this.
-r
+defaultR
 equestMethod
@@ -3445,17 +3445,24 @@
    this.
-r
+defaultR
 equestMe
@@ -3504,25 +3504,32 @@
    if (this.
-r
+defaultR
 esponseModel
@@ -3560,17 +3560,24 @@
    this.
-r
+defaultR
 esponseM

Make configuration method names more clear