
useDynLib(partykit, .registration = TRUE)

import("stats")
import("graphics")
import("grid")
import("Formula")
import("libcoin")
import("inum")
import("mvtnorm")
importFrom("survival",
  "survfit"
)
importFrom("rpart",
  "prune"
)
importFrom("grDevices",
  "gray.colors"
)
importFrom("utils",
  "capture.output",
  "head",
  "tail",
  "setTxtProgressBar",
  "txtProgressBar"
)

export(
  ## core infrastructure
  "party",
  "partynode",
  "partysplit",

  ## internal tree growing infrastructure
  "extree_data",
  "extree_fit",

  ## new ctree implementation
  "ctree",
  "ctree_control",
  "sctest.constparty",
  "varimp.constparty",

  ## new mob implementation
  "mob",
  "mob_control",
  "refit.modelparty",

  ## mobsters
  "lmtree",
  "glmtree",

  ## new cforest implementation
  "cforest",
  "predict.cforest",
  "varimp",
  "gettree",
  "varimp.cforest",
  "gettree.cforest",

  ## as/is class generics
  "as.party",  
  "as.partynode",
  "as.constparty",
  "as.simpleparty",
  "is.constparty",
  "is.partynode",
  "is.simpleparty",

  ## new generics
  "is.terminal",
  "nodeapply",
  "nodeids",
  "width",
  "nodeprune",

  ## exported methods (to facilitate re-use)
  "plot.party",
  "predict.party",
  "print.party",
  "plot.modelparty",
  "predict.modelparty",
  "print.modelparty",
  "sctest.modelparty",
  "prune.modelparty",
  "prune.lmtree",
  "nodeprune.party",

  ## workhorse infrastructure
  "breaks_split",
  "character_split",
  "formatinfo_node",
  "data_party",
  "data_party.default",
  "edge_simple",
  "fitted_node",
  "id_node",
  "index_split",
  "info_node",
  "info_split",
  "kidids_node",
  "kidids_split",
  "kids_node",
  "predict_party",
  "predict_party.default",
  "prob_split",
  "right_split",
  "split_node",
  "surrogates_node",
  "varid_split",

  ## visualization tools
  "node_barplot",
  "node_bivplot",
  "node_boxplot",
  "node_surv",
  "node_ecdf",
  "node_mvar",
  "node_inner",
  "node_party",
  "node_terminal",

  ## coercion methods for (non-imported) external classes
  "as.party.Weka_tree",
  "as.party.rpart",
  "as.party.XMLNode",
  "as.simpleparty.XMLNode",

  ## misc infrastructure
  "pmmlTreeModel",
  "get_paths",
  "model_frame_rpart"
)

## methods for class party
S3method("[", "party")
S3method("[[", "party")
S3method("as.simpleparty", "party")
S3method("depth", "party")
S3method("formula", "party")
S3method("getCall", "party")
S3method("getCall", "constparties")
S3method("length", "party")
S3method("model.frame", "party")
S3method("names", "party")
S3method("names<-", "party")
S3method("nodeapply", "party")
S3method("nodeids", "party")
S3method("predict", "party")
S3method("width", "party")
S3method("nodeprune", "party")
S3method("nodeprune", "partynode")
S3method("print", "party")
S3method("plot", "party")
S3method("data_party", "default")
S3method("predict_party", "default")

S3method("[[", "extree_data")
S3method("model.frame", "extree_data")

## methods for class partynode
S3method("[", "partynode")
S3method("[[", "partynode")
S3method("as.list", "partynode")
S3method("as.partynode", "partynode")
S3method("depth", "partynode")
S3method("is.terminal", "partynode")
S3method("length", "partynode")
S3method("nodeapply", "partynode")
S3method("nodeids", "partynode")
S3method("print", "partynode")
S3method("width", "partynode")

## methods for class constparty
S3method("as.simpleparty", "constparty")
S3method("plot", "constparty")
S3method("predict_party", "constparty")
S3method("print", "constparty")
S3method("varimp", "constparty")

## methods for class simpleparty
S3method("as.simpleparty", "simpleparty")
S3method("plot", "simpleparty")
S3method("predict_party", "simpleparty")
S3method("print", "simpleparty")

## methods for class modelparty
S3method("coef", "modelparty")
S3method("deviance", "modelparty")
S3method("fitted", "modelparty")
S3method("formula", "modelparty")
S3method("getCall", "modelparty")
S3method("logLik", "modelparty")
S3method("model.frame", "modelparty")
S3method("nobs", "modelparty")
S3method("residuals", "modelparty")
S3method("summary", "modelparty")
S3method("weights", "modelparty")
S3method("predict", "modelparty")
S3method("print", "modelparty")
S3method("plot", "modelparty")
S3method("prune", "modelparty")

## methods for class lmtree
S3method("plot", "lmtree")
S3method("predict", "lmtree")
S3method("print", "lmtree")
S3method("prune", "lmtree")

## methods for class glmtree
S3method("plot", "glmtree")
S3method("predict", "glmtree")
S3method("print", "glmtree")

## methods for class cforest
S3method("predict", "cforest")
S3method("varimp", "cforest")
S3method("gettree", "cforest")
S3method("model.frame", "cforest")

## misc methods
S3method("as.partynode", "list")
S3method("as.party", "Weka_tree")
S3method("as.party", "XMLNode")
S3method("as.simpleparty", "XMLNode")
S3method("as.party", "rpart")

## conditional registration of strucchange methods
if(getRversion() >= "3.6.0") {
  S3method(strucchange::sctest, "constparty")
  S3method(strucchange::sctest, "modelparty")
}
