from __future__ import annotations

import logging

from app.modules.agent.repository import AgentRepository

LOGGER = logging.getLogger(__name__)


class MetricsPersister:
    def __init__(self, repository: AgentRepository) -> None:
        self._repository = repository

    def save(
        self,
        *,
        task_id: str,
        dialog_session_id: str,
        rag_session_id: str,
        scenario: str,
        domain_id: str,
        process_id: str,
        quality: dict,
    ) -> None:
        try:
            self._repository.save_quality_metrics(
                task_id=task_id,
                dialog_session_id=dialog_session_id,
                rag_session_id=rag_session_id,
                scenario=scenario,
                domain_id=domain_id,
                process_id=process_id,
                quality=quality,
            )
        except Exception:
            LOGGER.exception("Failed to persist quality metrics: task_id=%s", task_id)
