#' Diagnostic and Visualization Plots for the Modified Topp-Leone Distribution
#'
#' Plot probability density function (PDF), cumulative distribution function (CDF),
#' survival function (SF), or hazard rate function (HRF) of the Modified Topp-Leone (MTL)
#' distribution for specified values of \code{alpha}.
#'
#' @param alpha Vector of shape parameter values (\code{alpha > 0}).
#' @param type Type of plot: \code{"pdf"}, \code{"cdf"}, \code{"sf"}, or \code{"hrf"}.
#' @param x_max Maximum value of x on the horizontal axis (default: 10).
#' @param n_points Number of evaluation points along the x-axis (default: 500).
#'
#' @return
#' No return value, called for side effects (produces a plot).
#'
#' @references
#' Singh, B., Tyagi, S., Singh, R. P., and Tyagi, A. (2025). Modified Topp-Leone
#' Distribution: Properties, Classical and Bayesian Estimation with Application to COVID-19
#' and Reliability Data. \emph{Thailand Statistician}, 23(1), 72-96.
#'
#' @author Shikhar Tyagi, Abhishek Tyagi, Arvind Pandey, Bhupendra Singh, Vrijesh Tripathi
#'
#' @examples
#' # Plot PDF for various values of alpha
#' plot_mtl(alpha = c(0.5, 1.5, 3.0, 10.0), type = "pdf", x_max = 5)
#'
#' # Plot HRF for various values of alpha
#' plot_mtl(alpha = c(0.5, 1.5, 3.0, 10.0), type = "hrf", x_max = 5)
#'
#' @name plot_mtl
#' @rdname plot_mtl
#' @export
plot_mtl <- function(alpha = c(0.5, 1.5, 3.0, 10.0),
                     type = c("pdf", "cdf", "sf", "hrf"),
                     x_max = 10, n_points = 500) {
  type <- match.arg(type)
  x_seq <- seq(0.01, x_max, length.out = n_points)
  
  colors <- c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#FFFF33")
  col_palette <- rep(colors, length.out = length(alpha))
  
  if (type == "pdf") {
    y_mat <- sapply(alpha, function(a) dmtl(x_seq, a))
    y_lim <- c(0, min(3, max(y_mat, na.rm = TRUE)))
    main_title <- "Modified Topp-Leone Density Function (PDF)"
    y_label <- "Density f(y)"
  } else if (type == "cdf") {
    y_mat <- sapply(alpha, function(a) pmtl(x_seq, a))
    y_lim <- c(0, 1)
    main_title <- "Modified Topp-Leone Distribution Function (CDF)"
    y_label <- "CDF F(y)"
  } else if (type == "sf") {
    y_mat <- sapply(alpha, function(a) smtl(x_seq, a))
    y_lim <- c(0, 1)
    main_title <- "Modified Topp-Leone Survival Function (SF)"
    y_label <- "Survival S(y)"
  } else if (type == "hrf") {
    y_mat <- sapply(alpha, function(a) hmtl(x_seq, a))
    y_lim <- c(0, min(3, max(y_mat[is.finite(y_mat)], na.rm = TRUE)))
    main_title <- "Modified Topp-Leone Hazard Rate Function (HRF)"
    y_label <- "Hazard Rate r(y)"
  }
  
  graphics::plot(x_seq, y_mat[, 1], type = "l", col = col_palette[1], lwd = 2,
                 ylim = y_lim, xlab = "y", ylab = y_label, main = main_title)
  
  if (length(alpha) > 1) {
    for (j in 2:length(alpha)) {
      graphics::lines(x_seq, y_mat[, j], col = col_palette[j], lwd = 2)
    }
  }
  
  legend_labels <- paste("alpha =", alpha)
  graphics::legend("topright", legend = legend_labels, col = col_palette, lwd = 2, bty = "n")
  
  invisible(NULL)
}
