# typed: strict
class Scraper::Metrics::GoodJobMetricsWithQueues < PrometheusExporter::Instrumentation::PeriodicStats
  extend T::Sig

  sig do
    params(
      args: T.untyped,
      client: T.nilable(PrometheusExporter::Client),
      frequency: Numeric,
      kwargs: T.untyped,
    ).void
  end
  def self.start(*args, client: nil, frequency: 5, **kwargs)
    client ||= PrometheusExporter::Client.default

    gauge =
      T.cast(
        client.register(
          :gauge,
          "good_job_queue_counts",
          "GoodJob queue counts",
        ),
        PrometheusExporter::Client::RemoteMetric,
      )

    worker_loop do
      SCOPES.each do |scope|
        GoodJob::Job
          .send(scope)
          .group(:queue_name, :job_class)
          .count
          .each do |(queue_name, job_class), count|
            gauge.observe(
              count,
              {
                queue_name: queue_name,
                job_class: job_class,
                scope: scope.to_s,
              },
            )
          end
      end
    end

    super
  end

  SCOPES = %i[all scheduled retried queued running finished succeeded discarded]

  sig { params(client: PrometheusExporter::Client).void }
  def collect(client)
  end
end
