#  
#  
#  
#  
#       month      DB_type     vlow      low      mid     high   vhigh
#  2016-04-01 Snowflake_TB  16.6300  16.6300  16.6300  16.6300  16.630
#  2017-04-01 Snowflake_TB  31.8991  34.5377  38.8541  45.3813  50.955
#  2018-04-01 Snowflake_TB  57.2098  66.7933  84.4609 116.2788 148.724
#  2019-04-01 Snowflake_TB 103.0329 131.4093 191.3592 322.6111 484.606
#  
#  
#  
#  ## Snowflake
#  Storage
#  Compute
#  
#  ## Vertica
#  Perpetual License @ 3 yr Ammort
#  Support  18% per year
#  Hardware per year
#  Number of Clusters
#  Human Resources
#  
#  3 node per 5 TB
#  1-8 TB per node
#  
#  Zynga does 
#  5 TB per node
#  
#  
#  1.4114
#  = B6 * 24 * 365 * sum(B2:B4)
#  
#  

snowflake_usage_costs_per_month <- function(huh = " ??? ") {

}

snowflake_cost_per_credit <- function() {
# snowflake_cost_per_credit <- function(credits=wh_usage_credits+(TB*c_per_TB), wh_usage_credits, TB, c_per_TB=100) {
# annual_credits <- credits * 12
# if (annual_credits < 200000)
#   ...

  return(1.25)
}

snowflake_stroage_costs_per_month <- function(TB_total, credit_price=1.35) {

#  dollars_per_TB <-  {
#    if (TB_total < 50)
#        100
#    else if (TB_total < 100)
#        75
#    else
#        65
#  }

  dollars_per_TB <- credit_price * 100

  return(TB_total * dollars_per_TB)
}

vertica_storage_cost_perpetual <- function(TB_incremental, license_cost_per_TB.perpetual=10000) {

  ## Shorthand
  TB <- TB_incremental

  ## Temporarily remove the NAs
  NAs <- is.na(TB)
  TB[NAs] <- 0.01

  ## Original Estimate. Pre late-april discussions
  #    dollars_per_TB <-  {
  #      ifelse(TB < 90, 8000,
  #        ifelse(TB < 500, 5500, 
  #           5000
  #        )
  #      )
  #    }

  dollars_per_TB <-  {
    ifelse(TB <= 150, 500000/150,
      ifelse(TB < 500, 500000/150 * 0.90, 
         500000/150 * 0.75
      )
    )
  }

  ## Put the NAs back
  TB[NAs] <- NA

  cost <- dollars_per_TB * TB
  return(cost)
}

vertica_support_costs_annually <- function(vertica.storage_costs, support_rate.annually=0.18) {

  support_rate.annually %<>% validPercentage()

  cost <- support_rate.annually * vertica.storage_costs
  return(cost)
}

vertica_DBA_resource_costs_monthly <- function(TB_total) {

  50000 / 12 * floor(TB_total / 150)

}

vertica_hw_costs_annually <- function(TB_total, new_node_every_X_TB_uncompressed=9, cost_per_node.annually=12364, clusters=2, QA_included=FALSE) {
## QA_included :: if TRUE, add one to clusters

  ## Shorthand
  TB <- TB_total   

  if (missing(clusters)) {
    clusters <- clusters + as.numeric(QA_included)
  } else {
    if (!missing(QA_included))
      warning("QA_included is ignored when clsuters is given explicitly")
  }

  nodes_per_cluster <- ceiling(TB / new_node_every_X_TB_uncompressed)
  total_number_of_nodes <- nodes_per_cluster * clusters

  cost <- cost_per_node.annually * total_number_of_nodes
  return(cost)  
}


#  DT.total_data_sizes[month %in% year_marks] [ DB_type != "Snowflake_TB"][, snowflake_monthly_stroage_costs := vertica_storage_cost_perpetual(mid)] []
#  DT.total_data_sizes[month %in% year_marks] [ DB_type == "Snowflake_TB"][, snowflake_monthly_stroage_costs := snowflake_stroage_costs_per_month(mid)] []
#  
#  
#  Storage -- 
#  100 Credits per TB per Month
#  
#  Compute -- 
#  function of the number of warehouses provisioned and how long provisioned
#  $ 1.35 per Credit
#  
#  
#  1 XS
#  2 S 
#  4
#  8 
#  16
#  32
#  64
#  
#  MCC 
