#==========================================================
# Duplicate Row Check
#==========================================================

#' Check Duplicate Rows
#'
#' Identifies duplicate rows in a dataset and reports their
#' row positions.
#'
#' @param data A data.frame.
#'
#' @return An object of class \code{DuplicateCheck}. The
#'   returned data.frame contains the row number and a logical
#'   indicator showing whether each row is a duplicate of an
#'   earlier row.
#'
#' @details
#' Duplicate rows are identified using \code{duplicated()}.
#' The first occurrence of a repeated row is not classified
#' as a duplicate. Only subsequent occurrences are marked as
#' duplicates.
#'
#' @examples
#' duplicate_check(iris)
#'
#' dat <- data.frame(
#'   x = c(1, 2, 2, 3),
#'   y = c("A", "B", "B", "C")
#' )
#'
#' duplicate_check(dat)
#'
#' @export

duplicate_check <- function(data) {

  #---------------------------------------------
  # Validation
  #---------------------------------------------
  validate_data(data)

  #---------------------------------------------
  # Duplicate detection
  #---------------------------------------------
  duplicate_status <- duplicated(data)

  #---------------------------------------------
  # Result
  #---------------------------------------------
  result <- data.frame(
    Row = seq_len(nrow(data)),
    Duplicate = duplicate_status,
    stringsAsFactors = FALSE
  )

  #---------------------------------------------
  # Class
  #---------------------------------------------
  class(result) <- c(
    "DuplicateCheck",
    "data.frame"
  )

  result
}
