defmodule MicrowavepropWeb.ContactLive.MechanismTest do
  use ExUnit.Case, async: true

  alias MicrowavepropWeb.ContactLive.Mechanism

  describe "label/1" do
    test "maps each classifier atom to a human-readable label" do
      assert Mechanism.label(:likely_rainscatter) == "Likely Rain Scatter"
      assert Mechanism.label(:rainscatter_possible) == "Rain Scatter Possible"
      assert Mechanism.label(:tropo_duct) == "Tropospheric Duct"
      assert Mechanism.label(:troposcatter) == "Troposcatter"
      assert Mechanism.label(:unknown) == "Unclassified"
    end

    test "falls back to 'Analyzing…' for nil / unrecognised values" do
      assert Mechanism.label(nil) == "Analyzing…"
      assert Mechanism.label(:some_new_atom_not_yet_mapped) == "Analyzing…"
    end
  end

  describe "badge_class/1" do
    test "returns a daisyUI badge class for every known mechanism" do
      for m <- [
            :likely_rainscatter,
            :rainscatter_possible,
            :tropo_duct,
            :troposcatter,
            :unknown,
            nil,
            :future_mechanism
          ] do
        cls = Mechanism.badge_class(m)
        assert is_binary(cls)
        assert String.starts_with?(cls, "badge-")
      end
    end

    test "distinguishes likely vs possible rain scatter visually" do
      # 'likely' is the confident variant (filled), 'possible' is outlined.
      assert Mechanism.badge_class(:likely_rainscatter) == "badge-info"
      assert Mechanism.badge_class(:rainscatter_possible) == "badge-info badge-outline"
    end
  end

  describe "explainer/1" do
    test "every classified mechanism gets a non-empty, single-sentence explainer" do
      for m <- [
            :likely_rainscatter,
            :rainscatter_possible,
            :tropo_duct,
            :troposcatter,
            :unknown
          ] do
        text = Mechanism.explainer(m)
        assert is_binary(text)
        assert text != ""
      end
    end

    test "unclassified / nil returns an empty string (no tooltip needed)" do
      assert Mechanism.explainer(nil) == ""
      assert Mechanism.explainer(:another_future_mechanism) == ""
    end

    test "tropo_duct explainer mentions the −157 N/km trapping threshold" do
      # Regression: we surface the numeric threshold so operators know
      # which physical quantity classifies them into the duct bucket.
      assert Mechanism.explainer(:tropo_duct) =~ "−157"
    end
  end
end
