from __future__ import annotations

from datetime import datetime, timezone

from analogai.deepthink.application.value_objects.user_agent import UserAgent
from analogai.deepthink.messaging.fact.utils.fact_context import use_turn_id
from analogai.deepthink.messaging.fact.services.fact_service import FactServicePort


class FactTurnTracker:
    def __init__(self, fact_service: FactServicePort):
        self._fact_service = fact_service

    def record_user_turn(self, input_text: str, user_agent: UserAgent):
        recorded_turn_id = self._fact_service.record_turn(
            user_id=user_agent.user_id,
            agent_id=user_agent.agent_id,
            text=input_text,
            role="user",
            user_name=user_agent.user_id,
            timestamp=datetime.now(timezone.utc),
        )
        return use_turn_id(recorded_turn_id)
