"""تست پارس و نرمال‌سازی Payamak — هم‌منطق torbatkar-back/SMSPanel/utils."""
from __future__ import annotations

from app.services.payamak_client import (
    _normalize_phone_for_sms,
    _parse_payamak_response_body,
    _payamak_pattern_logical_success,
)


def test_normalize_phone_eleven_digits():
    assert _normalize_phone_for_sms("09123456789") == "09123456789"
    assert _normalize_phone_for_sms("9123456789") == "09123456789"
    assert _normalize_phone_for_sms("+989123456789") == "09123456789"
    assert _normalize_phone_for_sms("00989123456789") == "09123456789"
    assert _normalize_phone_for_sms("invalid") is None


def test_parse_asmx_success():
    xml = """<?xml version="1.0"?>
    <SendByBaseNumberResponse>
      <SendByBaseNumberResult>98765432101234567</SendByBaseNumberResult>
    </SendByBaseNumberResponse>"""
    data = _parse_payamak_response_body(xml)
    ok, err = _payamak_pattern_logical_success(data)
    assert ok is True
    assert err is None


def test_parse_asmx_error():
    xml = "<SendByBaseNumberResult>-4</SendByBaseNumberResult>"
    data = _parse_payamak_response_body(xml)
    ok, err = _payamak_pattern_logical_success(data)
    assert ok is False
    assert err is not None
