defmodule Mix.Tasks.ResetEnrichment do
  @shortdoc "Reset weather/HRRR/IEMRE enrichment flags for re-processing"

  @moduledoc """
  Resets weather, HRRR, and IEMRE enrichment flags on all QSOs so the
  next enqueue worker run re-processes them with multi-point path data.

  Does NOT reset terrain_queued since terrain profiles are path-based (pos1→pos2)
  and don't change with multi-point enrichment.

      mix reset_enrichment
  """

  use Mix.Task

  import Ecto.Query

  alias Microwaveprop.Radio.Contact
  alias Microwaveprop.Repo

  @impl Mix.Task
  def run(_args) do
    Mix.Task.run("app.start")
    Oban.pause_all_queues(Oban)

    {count, _} =
      Contact
      |> where([q], q.weather_status != :pending or q.hrrr_status != :pending or q.iemre_status != :pending)
      |> Repo.update_all(set: [weather_status: "pending", hrrr_status: "pending", iemre_status: "pending"])

    Mix.shell().info("Reset enrichment status to :pending on #{count} contacts")
    :ok
  end
end
