defmodule Mix.Tasks.PropagationGrid do
  @shortdoc "Compute propagation scores for the CONUS grid"

  @moduledoc "Manually trigger propagation grid computation."
  use Mix.Task

  alias Microwaveprop.Workers.PropagationGridWorker

  @impl Mix.Task
  def run(_args) do
    # Pause all Oban queues so backfill jobs don't run alongside the grid fetch
    Application.put_env(
      :microwaveprop,
      Oban,
      Keyword.put(
        Application.get_env(:microwaveprop, Oban, []),
        :queues,
        false
      )
    )

    Mix.Task.run("app.start")

    IO.puts("Starting propagation grid computation...")

    PropagationGridWorker.perform(%Oban.Job{args: %{}})
    IO.puts("Done!")
  end
end
