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

from __future__ import annotations
from datetime import datetime
from enum import Enum
from honeyhive.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Any, Dict, List, Optional, TypedDict
from typing_extensions import NotRequired


class ResultsTypedDict(TypedDict):
    r"""The results of the evaluation (including pass/fails and metric aggregations)"""


class Results(BaseModel):
    r"""The results of the evaluation (including pass/fails and metric aggregations)"""


class EvaluationRunStatus(str, Enum):
    PENDING = "pending"
    COMPLETED = "completed"


class EvaluationRunTypedDict(TypedDict):
    run_id: NotRequired[str]
    project: NotRequired[str]
    r"""The UUID of the project this run is associated with"""
    created_at: NotRequired[datetime]
    r"""The date and time the run was created"""
    event_ids: NotRequired[List[str]]
    r"""The UUIDs of the sessions/events this run is associated with"""
    dataset_id: NotRequired[Nullable[str]]
    r"""The UUID of the dataset this run is associated with"""
    datapoint_ids: NotRequired[List[str]]
    r"""The UUIDs of the datapoints from the original dataset this run is associated with"""
    results: NotRequired[ResultsTypedDict]
    r"""The results of the evaluation (including pass/fails and metric aggregations)"""
    configuration: NotRequired[Dict[str, Any]]
    r"""The configuration being used for this run"""
    metadata: NotRequired[Dict[str, Any]]
    r"""Additional metadata for the run"""
    status: NotRequired[EvaluationRunStatus]
    name: NotRequired[str]
    r"""The name of the run to be displayed"""


class EvaluationRun(BaseModel):
    run_id: Optional[str] = None

    project: Optional[str] = None
    r"""The UUID of the project this run is associated with"""

    created_at: Optional[datetime] = None
    r"""The date and time the run was created"""

    event_ids: Optional[List[str]] = None
    r"""The UUIDs of the sessions/events this run is associated with"""

    dataset_id: OptionalNullable[str] = UNSET
    r"""The UUID of the dataset this run is associated with"""

    datapoint_ids: Optional[List[str]] = None
    r"""The UUIDs of the datapoints from the original dataset this run is associated with"""

    results: Optional[Results] = None
    r"""The results of the evaluation (including pass/fails and metric aggregations)"""

    configuration: Optional[Dict[str, Any]] = None
    r"""The configuration being used for this run"""

    metadata: Optional[Dict[str, Any]] = None
    r"""Additional metadata for the run"""

    status: Optional[EvaluationRunStatus] = None

    name: Optional[str] = None
    r"""The name of the run to be displayed"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "run_id",
            "project",
            "created_at",
            "event_ids",
            "dataset_id",
            "datapoint_ids",
            "results",
            "configuration",
            "metadata",
            "status",
            "name",
        ]
        nullable_fields = ["dataset_id"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

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

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
