"""Server alert IP resolution for Telegram."""

from server.utils.server_alert_ips import (
    classify_domain_ip,
    format_alert_ip_line,
    is_public_ip,
    merge_alert_ips,
)


def test_is_public_ip():
    assert is_public_ip("8.8.8.8") is True
    assert is_public_ip("172.21.171.82") is False


def test_classify_domain_ip():
    assert classify_domain_ip("8.8.8.8") == ("8.8.8.8", None)
    assert classify_domain_ip("172.21.171.82") == (None, "172.21.171.82")
    assert classify_domain_ip("host.example.com") == (None, None)


def test_merge_alert_ips_prefers_domain_public_over_agent():
    pub, priv = merge_alert_ips(
        domain="120.79.11.13",
        system_info={"public_ip": "1.2.3.4", "private_ip": "172.21.171.82"},
    )
    assert pub == "120.79.11.13"
    assert priv == "172.21.171.82"


def test_merge_alert_ips_agent_public_when_domain_private():
    pub, priv = merge_alert_ips(
        domain="172.21.171.82",
        system_info={"public_ip": "120.79.11.13", "private_ip": "172.21.171.82"},
    )
    assert pub == "120.79.11.13"
    assert priv == "172.21.171.82"


def test_format_alert_ip_line():
    assert format_alert_ip_line("1.2.3.4", "10.0.0.1") == "IP地址：1.2.3.4(外) 10.0.0.1(内)"
