#' F Distribution
#'
#' Makes an F distribution.
#'
#' @param df1,df2 Degrees of freedom of the numerator and denominator,
#' both single positive numerics.
#' @returns An F distribution.
#' @examples
#' dst_f(2, 3)
#' @export
dst_f <- function(df1, df2) {
  checkmate::assert_numeric(df1, 0, len = 1)
  checkmate::assert_numeric(df2, 0, len = 1)
  if (is.na(df1) || is.na(df2)) {
    return(dst_null())
  }
  distribution(
    .parameters = list(df1 = df1, df2 = df2),
    density = function(x) {
      stats::df(x, df1 = df1, df2 = df2)
    },
    cdf = function(x) {
      stats::pf(x, df1 = df1, df2 = df2)
    },
    quantile = function(p) {
      stats::qf(p, df1 = df1, df2 = df2)
    },
    realise = function(n) {
      stats::rf(n, df1 = df1, df2 = df2)
    },
    survival = function(x) {
      stats::pf(x, df1 = df1, df2 = df2, lower.tail = FALSE)
    },
    mean = ifelse(df2 > 2, df2 / (df2 - 2), NaN),
    variance = ifelse(
      df2 > 4,
      2 * df2^2 * (df1 + df2 - 2) / (df1 * (df2 - 2)^2 * (df2 - 4)),
      NaN
    ),
    skewness = ifelse(
      df2 > 6,
      (2 * df1 + df2 - 2) * sqrt(8 * (df2 - 4)) /
        ((df2 - 6) * sqrt(df1 * (df1 + df2 - 2))),
      NaN
    ),
    kurtosis_exc = ifelse(
      df2 > 8,
      12 * (df1 * (5 * df2 - 22) * (df1 + df2 - 2) + (df2 - 4) * (df2 - 2)^2) /
        (df1 * (df2 - 6) * (df2 - 8) * (df1 + df2 - 2)),
      NaN
    ),
    range = c(0, Inf),
    .name = "F",
    .vtype = "continuous"
  )
}
