defmodule Microwaveprop.Weather.MapLayersTest do
  use ExUnit.Case, async: true

  alias Microwaveprop.Weather.MapLayers

  describe "all/0" do
    test "returns a list of layer maps with required keys" do
      layers = MapLayers.all()

      assert is_list(layers)
      assert length(layers) > 0

      Enum.each(layers, fn layer ->
        assert Map.has_key?(layer, :id)
        assert Map.has_key?(layer, :label)
        assert Map.has_key?(layer, :unit)
        assert Map.has_key?(layer, :group)
        assert Map.has_key?(layer, :desc)
        assert is_binary(layer.id)
        assert is_binary(layer.label)
      end)
    end

    test "all layer ids are unique" do
      ids = MapLayers.all() |> Enum.map(& &1.id)
      assert length(ids) == Enum.uniq(ids) |> length()
    end

    test "includes temperature as the first layer" do
      assert hd(MapLayers.all()).id == "temperature"
    end
  end

  describe "default_id/0" do
    test "returns temperature" do
      assert MapLayers.default_id() == "temperature"
    end
  end

  describe "valid_id?/1" do
    test "returns true for known layer ids" do
      for layer <- MapLayers.all() do
        assert MapLayers.valid_id?(layer.id), "expected #{layer.id} to be valid"
      end
    end

    test "returns false for unknown layer ids" do
      refute MapLayers.valid_id?("nonexistent")
    end

    test "returns false for non-string input" do
      refute MapLayers.valid_id?(nil)
      refute MapLayers.valid_id?(123)
      refute MapLayers.valid_id?(:temperature)
    end
  end
end
