# This file was auto-generated by Fern from our API Definition.

from __future__ import annotations

import datetime as dt
import typing

import pydantic
import typing_extensions
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel, update_forward_refs
from ..core.serialization import FieldMetadata
from .google_protobuf_any import GoogleProtobufAny
from .owner import Owner
from .relations import Relations
from .replication import Replication
from .task_entity import TaskEntity
from .task_status import TaskStatus
from .task_version import TaskVersion


class Task(UniversalBaseModel):
    """
    A Task is something an agent can be asked to do.
    """

    version: typing.Optional[TaskVersion] = pydantic.Field(default=None)
    """
    Version of this Task.
    """

    display_name: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="displayName")] = (
        pydantic.Field(default=None)
    )
    """
    DEPRECATED: Human readable display name for this Task, should be short (<100 chars).
    """

    specification: typing.Optional[GoogleProtobufAny] = pydantic.Field(default=None)
    """
    Full Task parameterization.
    """

    created_by: typing_extensions.Annotated[typing.Optional["Principal"], FieldMetadata(alias="createdBy")] = (
        pydantic.Field(default=None)
    )
    """
    Records who created this Task. This field will not change after the Task has been created.
    """

    last_updated_by: typing_extensions.Annotated[typing.Optional["Principal"], FieldMetadata(alias="lastUpdatedBy")] = (
        pydantic.Field(default=None)
    )
    """
    Records who updated this Task last.
    """

    last_update_time: typing_extensions.Annotated[
        typing.Optional[dt.datetime], FieldMetadata(alias="lastUpdateTime")
    ] = pydantic.Field(default=None)
    """
    Records the time of last update.
    """

    status: typing.Optional[TaskStatus] = pydantic.Field(default=None)
    """
    The status of this Task.
    """

    scheduled_time: typing_extensions.Annotated[typing.Optional[dt.datetime], FieldMetadata(alias="scheduledTime")] = (
        pydantic.Field(default=None)
    )
    """
    If the Task has been scheduled to execute, what time it should execute at.
    """

    relations: typing.Optional[Relations] = pydantic.Field(default=None)
    """
    Any related Tasks associated with this, typically includes an assignee for this Task and/or a parent.
    """

    description: typing.Optional[str] = pydantic.Field(default=None)
    """
    Longer, free form human readable description of this Task
    """

    is_executed_elsewhere: typing_extensions.Annotated[
        typing.Optional[bool], FieldMetadata(alias="isExecutedElsewhere")
    ] = pydantic.Field(default=None)
    """
    If set, execution of this Task is managed elsewhere, not by Task Manager.
     In other words, Task manager will not attempt to update the assigned agent with execution instructions.
    """

    create_time: typing_extensions.Annotated[typing.Optional[dt.datetime], FieldMetadata(alias="createTime")] = (
        pydantic.Field(default=None)
    )
    """
    Time of Task creation.
    """

    replication: typing.Optional[Replication] = pydantic.Field(default=None)
    """
    If populated, designates this to be a replicated Task.
    """

    initial_entities: typing_extensions.Annotated[
        typing.Optional[typing.List[TaskEntity]], FieldMetadata(alias="initialEntities")
    ] = pydantic.Field(default=None)
    """
    If populated, indicates an initial set of entities that can be used to execute an entity aware task
     For example, an entity Objective, an entity Keep In Zone, etc.
     These will not be updated during execution. If a taskable agent needs continuous updates on the entities from the
     COP, can call entity-manager, or use an AlternateId escape hatch.
    """

    owner: typing.Optional[Owner] = pydantic.Field(default=None)
    """
    The networked owner of this Task. It is used to ensure that linear writes occur on the node responsible
     for replication of task data to other nodes running Task Manager.
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow


from .principal import Principal  # noqa: E402, F401, I001
from .entity import Entity  # noqa: E402, F401, I001
from .override import Override  # noqa: E402, F401, I001
from .overrides import Overrides  # noqa: E402, F401, I001

update_forward_refs(Task)
