package hex.schemas;

import hex.tree.gbm.GBM;
import hex.tree.gbm.GBMModel.GBMParameters;
import water.api.API;
import water.api.ModelParametersSchema;
import water.fvec.Frame;
import water.util.PojoUtils;

public class GBMV2 extends ModelBuilderSchema<GBM,GBMV2,GBMV2.GBMParametersV2> {

  public static final class GBMParametersV2 extends ModelParametersSchema<GBMParameters, GBMParametersV2> {
    public String[] fields() { return new String[] {
        "destination_key",
        "training_frame",
        "validation_frame",
        "response_column",
        "ntrees",
        "max_depth",
        "min_rows",
        "nbins",
        "learn_rate",
        "loss",
        "variable_importance",
        "seed"}; }

    // Input fields
    @API(help="Number of trees. Grid Search, comma sep values:50,100,150,200")
    public int ntrees;

    @API(help="Learning rate from 0.0 to 1.0")
    public float learn_rate;

    @API(help = "Loss function", values = { "AUTO", "Bernoulli" })
    public GBMParameters.Family loss;

    @API(help = "RNG Seed for balancing classes", level = API.Level.expert)
    public long seed;

    @API(help = "Compute variable importance", level = API.Level.critical)
    public boolean variable_importance;

    @Override public GBMParametersV2 fillFromImpl(GBMParameters parms) {
      super.fillFromImpl(parms);
      loss = GBMParameters.Family.AUTO;
      variable_importance = parms._importance;
      return this;
    }

    public GBMParameters createImpl() {
      GBMParameters impl = new GBMParameters();
      PojoUtils.copyProperties(impl, this, PojoUtils.FieldNaming.DEST_HAS_UNDERSCORES);
      impl._importance = this.variable_importance;

      // Sigh:
      impl._train = (this.training_frame == null ? null : this.training_frame._key);
      impl._valid = (this.validation_frame == null ? null : this.validation_frame._key);

      return impl;
    }
  }

  //==========================
  // Custom adapters go here

  @Override public GBMParametersV2 createParametersSchema() { return new GBMParametersV2(); }

  // TODO: refactor ModelBuilder creation
  // TODO: defaults should only be in the impl, not duplicated in the API layer
  @Override public GBM createImpl() {
    GBMParameters parms = parameters.createImpl();
    return new GBM(parms);
  }

  // TODO: UGH
  // Return a URL to invoke GBM on this Frame
  @Override protected String acceptsFrame( Frame fr ) { return "/v2/GBM?training_frame="+fr._key; }
}

@@ -768,16 +768,17 @@
 f trees.
+ 
  Grid Se
@@ -837,24 +837,366 @@
 nt ntrees;%0A%0A
+    @API(help=%22Maximum tree depth.  Grid Search, comma sep values:5,7%22)%0A    public int max_depth;%0A%0A    @API(help=%22Fewest allowed observations in a leaf (in R called 'nodesize'). Grid Search, comma sep values%22)%0A    public int min_rows;%0A%0A    @API(help=%22Build a histogram of this many bins, then split at the best point%22)%0A    public int nbins;%0A%0A
     @API(hel

Add matching parameter API fields