#pragma once

#include "metric.hpp"

/**
 * @brief A metric collector for standard process-level statistics.
 *
 * Gathers metrics like CPU usage, memory, and file descriptors by reading
 * files from the /proc filesystem.
 */
struct ProcessCollector : public metric::Collector {
  /**
   * @brief Constructs the collector and initializes the process metrics.
   */
  ProcessCollector();

  /**
   * @brief Called by the metrics system to update the process metrics.
   */
  void collect() override;

private:
  // Metrics for process statistics
  metric::Counter cpu_seconds_total_;
  metric::Gauge resident_memory_bytes_;
  metric::Gauge virtual_memory_bytes_;
  metric::Gauge open_fds_;
  metric::Gauge max_fds_;
  metric::Gauge start_time_seconds_;

  // Additional process metrics from /proc/self/status
  metric::Gauge threads_;
  metric::Counter context_switches_total_voluntary_;
  metric::Counter context_switches_total_nonvoluntary_;

  // Page fault metrics from /proc/self/stat
  metric::Counter page_faults_total_minor_;
  metric::Counter page_faults_total_major_;

  // Last observed values for calculating counter increments
  unsigned long long last_total_ticks_ = 0;
  unsigned long long last_minor_faults_ = 0;
  unsigned long long last_major_faults_ = 0;
  unsigned long long last_voluntary_context_switches_ = 0;
  unsigned long long last_nonvoluntary_context_switches_ = 0;
  bool start_time_set_ = false;
};
