"""HandlerContext — immutable bundle of model callbacks shared by all handlers."""
from __future__ import annotations

import time
from dataclasses import dataclass, field

from ._types import (
    EmbedFn,
    InferFn,
    InferImageEditFn,
    InferImageFn,
    InferStreamFn,
    SynthesizeFn,
    TranscribeFn,
)


@dataclass(frozen=True)
class HandlerContext:
    model_id: str
    default_max_tokens: int
    category: str = "text-generation"
    infer: InferFn | None = None
    infer_stream: InferStreamFn | None = None
    embed: EmbedFn | None = None
    infer_image: InferImageFn | None = None
    infer_image_edit: InferImageEditFn | None = None
    transcribe: TranscribeFn | None = None
    synthesize: SynthesizeFn | None = None
    created: int = field(default_factory=lambda: int(time.time()))

    @property
    def model_obj(self) -> dict:
        return {
            "id": self.model_id,
            "object": "model",
            "created": self.created,
            "owned_by": "llmpm",
        }
