defmodule Berrypod.Workers.RedirectPrunerWorker do
  @moduledoc """
  Weekly Oban cron job that prunes auto-created redirects
  with zero hits older than 90 days.
  """

  use Oban.Worker, queue: :default, max_attempts: 1

  @impl Oban.Worker
  def perform(_job) do
    {:ok, count} = Berrypod.Redirects.prune_stale_redirects()

    if count > 0 do
      require Logger
      Logger.info("Pruned #{count} stale redirect(s) with 0 hits")
    end

    :ok
  end
end
