 defmodule FarmbotOS.Platform.Target.Configurator.VintageNetworkLayer do
+  require FarmbotCore.Logger
   @behaviour FarmbotOS.Configurator.NetworkLayer
 
   @impl FarmbotOS.Configurator.NetworkLayer


  @impl FarmbotOS.Configurator.NetworkLayer
  def scan(ifname) do
    _ = VintageNet.scan(ifname)
    [{_, aps}] = VintageNet.get_by_prefix(["interface", ifname, "wifi", "access_points"])

    Enum.map(aps, fn %{bssid: bssid, ssid: ssid, signal_percent: signal, flags: flags} ->
      %{

    end)
  end

  defp do_scan(ifname) do
    _ = VintageNet.scan(ifname)

    case VintageNet.get_by_prefix(["interface", ifname, "wifi", "access_points"]) do
      [{_, []}] ->
        FarmbotCore.Logger.debug(3, "AP list was empty. Trying again")
        Process.sleep(100)
        do_scan(ifname)

      [{_, [_ | _] = aps}] ->
        {:ok, aps}

      _ ->
        :error
    end
  end

  defp flags_to_security([:wpa2_psk_ccmp | _]), do: "WPA-PSK"
  defp flags_to_security([:wpa2_psk_ccmp_tkip | _]), do: "WPA-PSK"
  defp flags_to_security([:wpa_psk_ccmp | _]), do: "WPA-PSK"
