defmodule Microwaveprop.ValkeyTest do
  use ExUnit.Case, async: true

  alias Microwaveprop.Valkey

  describe "child_spec/1" do
    test "returns a valid child spec map" do
      spec = Valkey.child_spec([])

      assert spec.id == Valkey
      assert spec.type == :worker
      assert spec.restart == :permanent
    end
  end

  describe "configured?/0" do
    test "returns false when Valkey is not configured" do
      assert Valkey.configured?() == false
    end
  end

  describe "get/1" do
    test "returns error when not configured" do
      assert {:error, :not_configured} = Valkey.get("test_key")
    end
  end

  describe "mget/1" do
    test "empty list returns {:ok, []}" do
      assert Valkey.mget([]) == {:ok, []}
    end

    test "returns error when not configured" do
      assert {:error, :not_configured} = Valkey.mget(["key1", "key2"])
    end
  end

  describe "set/3" do
    test "returns error when not configured" do
      assert {:error, :not_configured} = Valkey.set("key", "value", 3600)
    end
  end

  describe "mset_with_ttl/2" do
    test "empty list returns :ok" do
      assert Valkey.mset_with_ttl([], 3600) == :ok
    end

    test "returns error when not configured" do
      pairs = [{"key1", "val1"}, {"key2", "val2"}]
      assert {:error, :not_configured} = Valkey.mset_with_ttl(pairs, 3600)
    end
  end

  describe "zadd/3" do
    test "returns error when not configured" do
      assert {:error, :not_configured} = Valkey.zadd("zset", 1.0, "member")
    end
  end

  describe "zrevrange/3" do
    test "returns error when not configured" do
      assert {:error, :not_configured} = Valkey.zrevrange("zset", 0, 10)
    end
  end

  describe "zrangebyscore/3" do
    test "returns error when not configured" do
      assert {:error, :not_configured} = Valkey.zrangebyscore("zset", "0", "100")
    end
  end

  describe "zrem/2" do
    test "empty list returns :ok" do
      assert Valkey.zrem("zset", []) == :ok
    end

    test "returns error when not configured" do
      assert {:error, :not_configured} = Valkey.zrem("zset", ["member1"])
    end
  end

  describe "del/1" do
    test "empty list returns :ok" do
      assert Valkey.del([]) == :ok
    end

    test "returns error when not configured" do
      assert {:error, :not_configured} = Valkey.del(["key1"])
    end
  end

  describe "scan_match/1" do
    test "returns error when not configured" do
      assert {:error, :not_configured} = Valkey.scan_match("pattern:*")
    end
  end
end
