"""Resolve the phone selector once, keeping the backend credential server-side.""" import httpx from pydantic import ValidationError from vocero_api.core import config as settings from vocero_api.models.mcp import BackendLogin, IntegrationError async def login(phone_number: str) -> BackendLogin: if not settings.S2S_LOGIN_BY_PHONE: raise IntegrationError(503, "El acceso por teléfono no está configurado.") try: async with httpx.AsyncClient(timeout=10, follow_redirects=False) as client: response = await client.post(settings.S2S_LOGIN_BY_PHONE, json={"phoneNumber": phone_number}) if response.status_code in {401, 403, 404, 422}: raise IntegrationError(401, "No se pudo iniciar sesión con este número de teléfono.") response.raise_for_status() return BackendLogin.model_validate(response.json()) except (httpx.HTTPError, ValidationError, ValueError) as exc: raise IntegrationError(502, "No se pudo validar la sesión con AquaPortal.") from exc