"""Task result data model."""

from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from typing import Optional


@dataclass
class TaskResult:
    id: str
    task_id: str
    provider_id: str
    lean_code: str
    raw_output: str
    flops_used: int
    mflops_used: int
    billed_mflops: int = 0
    prompt_tokens: int = 0
    generated_tokens: int = 0
    model_params: int = 0
    prefill_eval_ms: float = 0.0
    decode_eval_ms: float = 0.0
    total_eval_ms: float = 0.0
    created_at: Optional[datetime] = None

    @classmethod
    def from_row(cls, row: dict) -> TaskResult:
        return cls(
            id=row["id"],
            task_id=row["task_id"],
            provider_id=row["provider_id"],
            lean_code=row.get("lean_code", ""),
            raw_output=row.get("raw_output", ""),
            flops_used=row.get("flops_used", 0),
            mflops_used=row.get("mflops_used", 0),
            billed_mflops=row.get("billed_mflops", 0),
            prompt_tokens=row.get("prompt_tokens", 0),
            generated_tokens=row.get("generated_tokens", 0),
            model_params=row.get("model_params", 0),
            prefill_eval_ms=row.get("prefill_eval_ms", 0.0),
            decode_eval_ms=row.get("decode_eval_ms", 0.0),
            total_eval_ms=row.get("total_eval_ms", 0.0),
            created_at=row.get("created_at"),
        )
