from __future__ import annotations

from typing import Any

from .models import HistoryRecord


class HistoryRecorder:
    def __init__(self, run_id: str, workflow_name: str):
        self.run_id = run_id
        self.workflow_name = workflow_name
        self.records: list[HistoryRecord] = []

    def record(
        self,
        record_type: str,
        *,
        task_name: str | None = None,
        event_id: str | None = None,
        event_name: str | None = None,
        attempt: int | None = None,
        details: dict[str, Any] | None = None,
    ) -> HistoryRecord:
        record = HistoryRecord(
            record_type=record_type,
            run_id=self.run_id,
            workflow_name=self.workflow_name,
            task_name=task_name,
            event_id=event_id,
            event_name=event_name,
            attempt=attempt,
            details=details or {},
        )
        self.records.append(record)
        return record
