defmodule Mv.Vereinfacht.ClientTest do
  @moduledoc """
  Tests for Mv.Vereinfacht.Client.

  Only tests the "not configured" path; no real HTTP calls. Config reads from
  ENV first, then from Settings (DB), so we use DataCase so get_settings() is available.
  """
  use Mv.DataCase, async: false

  alias Mv.Vereinfacht.Client

  setup do
    clear_vereinfacht_env()
    :ok
  end

  describe "create_contact/1" do
    test "returns {:error, :not_configured} when Vereinfacht is not configured" do
      member = build_member_struct()

      assert Client.create_contact(member) == {:error, :not_configured}
    end
  end

  describe "update_contact/2" do
    test "returns {:error, :not_configured} when Vereinfacht is not configured" do
      member = build_member_struct()

      assert Client.update_contact("123", member) == {:error, :not_configured}
    end
  end

  defp build_member_struct do
    %{
      first_name: "Test",
      last_name: "User",
      email: "test@example.com",
      street: "Street 1",
      house_number: "2",
      postal_code: "12345",
      city: "Berlin"
    }
  end

  defp clear_vereinfacht_env do
    System.delete_env("VEREINFACHT_API_URL")
    System.delete_env("VEREINFACHT_API_KEY")
    System.delete_env("VEREINFACHT_CLUB_ID")
  end
end
