import uuid
from datetime import datetime
from typing import Optional
from uuid import UUID

from pydantic import Field
from tacoq.core.models.avro_serializable_base_model import (
    AvroSerializableBaseModel,
    avro_schema_path,
)

from tacoq.core.models.task import TaskInput


@avro_schema_path("schemas/avro/task_assignment_update.json")
class TaskAssignmentUpdate(AvroSerializableBaseModel):
    """Update of a task being assigned to a worker."""

    id: UUID = Field(default_factory=uuid.uuid4)
    """The unique ID of the task. Generated by the client so that it can be 
    communicated to the relay and the workers directly."""

    task_kind: str
    """ The kind of the task - dictates which function the worker will execute 
    to handle it."""

    worker_kind: str
    """ The kind of worker that will execute the task. Dictates the queue that 
    the task will be routed through. """

    created_at: datetime = Field(default_factory=lambda: datetime.now())
    """ The time the task was created at. """

    input_data: Optional[TaskInput] = Field(default=None)
    """ The input data of the task."""

    priority: int
    """ The priority of the task, ranging from 0 (lowest) to 255 (highest). """

    ttl_duration: int
    """ The duration of how long the task should live after it has been completed."""

    otel_ctx_carrier: dict[str, str] = Field(default_factory=dict)
    """ The OpenTelemetry context carrier for the task. """
