"""Tests for HTTPException detail Chinese translation."""

from server.utils.http_errors_zh import (
    auth_failure_detail,
    translate_http_detail,
    translate_http_detail_str,
)


def test_translate_server_not_found():
    assert translate_http_detail_str("Server not found") == "服务器不存在"


def test_translate_auth_jwt_header():
    assert translate_http_detail_str("Missing Authorization header") == "缺少 Authorization 请求头"


def test_translate_chinese_unchanged():
    s = "NEXUS_API_BASE_URL 未配置"
    assert translate_http_detail_str(s) == s


def test_translate_command_failed_pattern():
    assert translate_http_detail_str("Command failed (exit 1)") == "命令失败（退出码 1）"


def test_translate_immutable_setting_pattern():
    msg = "Setting 'secret_key' is immutable and cannot be modified via API"
    assert translate_http_detail_str(msg) == "设置项「secret_key」不可通过 API 修改"


def test_translate_dict_message_key():
    out = translate_http_detail({"message": "Script not found", "code": 404})
    assert out["message"] == "脚本不存在"
    assert out["code"] == 404


def test_translate_list_detail():
    out = translate_http_detail(["Server not found", "已配置"])
    assert out == ["服务器不存在", "已配置"]


def test_auth_failure_detail_prefers_message():
    assert auth_failure_detail({"message": "用户名或密码错误"}) == "用户名或密码错误"


def test_auth_failure_detail_maps_reason_code():
    assert auth_failure_detail({"reason": "admin_not_found"}) == "管理员不存在"


def test_auth_failure_detail_fallback_zh():
    assert auth_failure_detail({}, fallback="登录失败") == "登录失败"
