"""Unit tests for `app.services.estimator._qc_geo_to_precision`.

Pure-function mapping DaData qc_geo → address-precision indicator:
- 0 → "house"   (дом распознан точно)
- 1 → "street"  (до улицы)
- 2/3/4/5 → "approximate"  (населённый пункт / город / регион / не распознан)
- None → None   (DaData не отрабатывала)

Чистый unit-тест: без БД и сети.
"""

from __future__ import annotations

import os
import sys
from unittest.mock import MagicMock

import pytest

# DATABASE_URL required by config before any app import (см. test_dadata.py).
os.environ.setdefault("DATABASE_URL", "postgresql+psycopg://test:test@localhost:5432/test")

# WeasyPrint stub — not installed in CI без GTK (consistent с test_dadata.py).
_wp_mock = MagicMock()
sys.modules.setdefault("weasyprint", _wp_mock)

from app.services.estimator import _qc_geo_to_precision  # noqa: E402


@pytest.mark.parametrize(
    ("qc_geo", "expected"),
    [
        (0, "house"),
        (1, "street"),
        (2, "approximate"),
        (3, "approximate"),
        (4, "approximate"),
        (5, "approximate"),
        (None, None),
    ],
)
def test_qc_geo_to_precision(qc_geo: int | None, expected: str | None) -> None:
    assert _qc_geo_to_precision(qc_geo) == expected
