from __future__ import annotations

import structlog

from adapter.matrix.store import get_room_meta
from core.store import StateStore

logger = structlog.get_logger(__name__)


async def resolve_chat_id(store: StateStore, room_id: str, matrix_user_id: str) -> str:
    meta = await get_room_meta(store, room_id)
    if meta and meta.get("chat_id"):
        return meta["chat_id"]

    logger.warning("unregistered_room", room_id=room_id, user=matrix_user_id)
    return f"unregistered:{room_id}"
