"""Tests for LangfuseConfig and client resolution."""

from __future__ import annotations

from dr_langfuse.client import LangfuseConfig


def test_langfuse_config_from_env() -> None:
    cfg = LangfuseConfig.from_env(
        {
            "LANGFUSE_PUBLIC_KEY": "pk",
            "LANGFUSE_SECRET_KEY": "sk",
            "LANGFUSE_HOST": "https://cloud.langfuse.com",
        }
    )
    assert cfg.public_key == "pk"
    assert cfg.secret_key == "sk"
    assert cfg.host == "https://cloud.langfuse.com"


def test_langfuse_config_prefers_base_url_over_host() -> None:
    cfg = LangfuseConfig.from_env(
        {
            "LANGFUSE_PUBLIC_KEY": "pk",
            "LANGFUSE_SECRET_KEY": "sk",
            "LANGFUSE_BASE_URL": "https://base.langfuse.com",
            "LANGFUSE_HOST": "https://host.langfuse.com",
        }
    )
    assert cfg.host == "https://base.langfuse.com"


def test_langfuse_config_from_env_missing_keys() -> None:
    cfg = LangfuseConfig.from_env({})
    assert cfg.public_key is None
    assert cfg.secret_key is None
    assert cfg.host is None
