"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .entitytype import EntityType
from .filetype import FileType
from .status import Status
from .taskstatus import TaskStatus
from .tasktype import TaskType
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Any, Dict, Optional
from typing_extensions import NotRequired, TypedDict


class DtoTaskResponseTypedDict(TypedDict):
    completed_at: NotRequired[str]
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    entity_type: NotRequired[EntityType]
    environment_id: NotRequired[str]
    error_summary: NotRequired[str]
    failed_at: NotRequired[str]
    failed_records: NotRequired[int]
    file_name: NotRequired[str]
    file_type: NotRequired[FileType]
    file_url: NotRequired[str]
    id: NotRequired[str]
    metadata: NotRequired[Dict[str, Any]]
    processed_records: NotRequired[int]
    scheduled_task_id: NotRequired[str]
    started_at: NotRequired[str]
    status: NotRequired[Status]
    successful_records: NotRequired[int]
    task_status: NotRequired[TaskStatus]
    task_type: NotRequired[TaskType]
    tenant_id: NotRequired[str]
    total_records: NotRequired[int]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]
    workflow_id: NotRequired[str]


class DtoTaskResponse(BaseModel):
    completed_at: Optional[str] = None

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    entity_type: Optional[EntityType] = None

    environment_id: Optional[str] = None

    error_summary: Optional[str] = None

    failed_at: Optional[str] = None

    failed_records: Optional[int] = None

    file_name: Optional[str] = None

    file_type: Optional[FileType] = None

    file_url: Optional[str] = None

    id: Optional[str] = None

    metadata: Optional[Dict[str, Any]] = None

    processed_records: Optional[int] = None

    scheduled_task_id: Optional[str] = None

    started_at: Optional[str] = None

    status: Optional[Status] = None

    successful_records: Optional[int] = None

    task_status: Optional[TaskStatus] = None

    task_type: Optional[TaskType] = None

    tenant_id: Optional[str] = None

    total_records: Optional[int] = None

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    workflow_id: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "completed_at",
                "created_at",
                "created_by",
                "entity_type",
                "environment_id",
                "error_summary",
                "failed_at",
                "failed_records",
                "file_name",
                "file_type",
                "file_url",
                "id",
                "metadata",
                "processed_records",
                "scheduled_task_id",
                "started_at",
                "status",
                "successful_records",
                "task_status",
                "task_type",
                "tenant_id",
                "total_records",
                "updated_at",
                "updated_by",
                "workflow_id",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
