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

from ..core.pydantic_utilities import UniversalBaseModel
import typing
import pydantic
from .task_navigation_payload import TaskNavigationPayload
from .proxy_location import ProxyLocation
from .task_extracted_information_schema import TaskExtractedInformationSchema
from .task_type import TaskType
import datetime as dt
from .task_status import TaskStatus
from .task_extracted_information import TaskExtractedInformation
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class Task(UniversalBaseModel):
    title: typing.Optional[str] = pydantic.Field(default=None)
    """
    The title of the task.
    """

    url: str = pydantic.Field()
    """
    Starting URL for the task.
    """

    webhook_callback_url: typing.Optional[str] = pydantic.Field(default=None)
    """
    The URL to call when the task is completed.
    """

    totp_verification_url: typing.Optional[str] = None
    totp_identifier: typing.Optional[str] = None
    navigation_goal: typing.Optional[str] = pydantic.Field(default=None)
    """
    The user's goal for the task.
    """

    data_extraction_goal: typing.Optional[str] = pydantic.Field(default=None)
    """
    The user's goal for data extraction.
    """

    navigation_payload: typing.Optional[TaskNavigationPayload] = pydantic.Field(default=None)
    """
    The user's details needed to achieve the task.
    """

    error_code_mapping: typing.Optional[typing.Dict[str, typing.Optional[str]]] = pydantic.Field(default=None)
    """
    The mapping of error codes and their descriptions.
    """

    proxy_location: typing.Optional[ProxyLocation] = pydantic.Field(default=None)
    """
    The location of the proxy to use for the task.
    """

    extracted_information_schema: typing.Optional[TaskExtractedInformationSchema] = pydantic.Field(default=None)
    """
    The requested schema of the extracted information.
    """

    complete_criterion: typing.Optional[str] = pydantic.Field(default=None)
    """
    Criterion to complete
    """

    terminate_criterion: typing.Optional[str] = pydantic.Field(default=None)
    """
    Criterion to terminate
    """

    task_type: typing.Optional[TaskType] = pydantic.Field(default=None)
    """
    The type of the task
    """

    application: typing.Optional[str] = pydantic.Field(default=None)
    """
    The application for which the task is running
    """

    created_at: dt.datetime = pydantic.Field()
    """
    The creation datetime of the task.
    """

    modified_at: dt.datetime = pydantic.Field()
    """
    The modification datetime of the task.
    """

    task_id: str = pydantic.Field()
    """
    The ID of the task.
    """

    status: TaskStatus = pydantic.Field()
    """
    The status of the task.
    """

    extracted_information: typing.Optional[TaskExtractedInformation] = pydantic.Field(default=None)
    """
    The extracted information from the task.
    """

    failure_reason: typing.Optional[str] = pydantic.Field(default=None)
    """
    The reason for the task failure.
    """

    organization_id: typing.Optional[str] = None
    workflow_run_id: typing.Optional[str] = None
    order: typing.Optional[int] = None
    retry: typing.Optional[int] = None
    max_steps_per_run: typing.Optional[int] = None
    errors: typing.Optional[typing.List[typing.Dict[str, typing.Optional[typing.Any]]]] = None

    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
