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

from __future__ import annotations

import datetime as dt
import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from .llm_as_judge_code_public import LlmAsJudgeCodePublic
from .project_reference_public import ProjectReferencePublic
from .span_filter_public import SpanFilterPublic
from .span_llm_as_judge_code_public import SpanLlmAsJudgeCodePublic
from .span_user_defined_metric_python_code_public import SpanUserDefinedMetricPythonCodePublic
from .trace_filter_public import TraceFilterPublic
from .trace_thread_filter_public import TraceThreadFilterPublic
from .trace_thread_llm_as_judge_code_public import TraceThreadLlmAsJudgeCodePublic
from .trace_thread_user_defined_metric_python_code_public import TraceThreadUserDefinedMetricPythonCodePublic
from .user_defined_metric_python_code_public import UserDefinedMetricPythonCodePublic


class Base(UniversalBaseModel):
    id: typing.Optional[str] = None
    project_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    Primary project ID (legacy field for backwards compatibility)
    """

    project_name: typing.Optional[str] = pydantic.Field(default=None)
    """
    Primary project name (legacy field for backwards compatibility)
    """

    projects: typing.Optional[typing.List[ProjectReferencePublic]] = pydantic.Field(default=None)
    """
    Projects assigned to this rule (unique, sorted alphabetically by name)
    """

    name: str
    sampling_rate: typing.Optional[float] = None
    enabled: typing.Optional[bool] = None
    created_at: typing.Optional[dt.datetime] = None
    created_by: typing.Optional[str] = None
    last_updated_at: typing.Optional[dt.datetime] = None
    last_updated_by: typing.Optional[str] = None
    action: typing.Literal["evaluator"] = "evaluator"

    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


class AutomationRuleEvaluatorPublic_LlmAsJudge(Base):
    type: typing.Literal["llm_as_judge"] = "llm_as_judge"
    filters: typing.Optional[typing.List[TraceFilterPublic]] = None
    code: typing.Optional[LlmAsJudgeCodePublic] = 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


class AutomationRuleEvaluatorPublic_UserDefinedMetricPython(Base):
    type: typing.Literal["user_defined_metric_python"] = "user_defined_metric_python"
    filters: typing.Optional[typing.List[TraceFilterPublic]] = None
    code: typing.Optional[UserDefinedMetricPythonCodePublic] = 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


class AutomationRuleEvaluatorPublic_TraceThreadLlmAsJudge(Base):
    type: typing.Literal["trace_thread_llm_as_judge"] = "trace_thread_llm_as_judge"
    filters: typing.Optional[typing.List[TraceThreadFilterPublic]] = None
    code: typing.Optional[TraceThreadLlmAsJudgeCodePublic] = 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


class AutomationRuleEvaluatorPublic_TraceThreadUserDefinedMetricPython(Base):
    type: typing.Literal["trace_thread_user_defined_metric_python"] = "trace_thread_user_defined_metric_python"
    filters: typing.Optional[typing.List[TraceThreadFilterPublic]] = None
    code: typing.Optional[TraceThreadUserDefinedMetricPythonCodePublic] = 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


class AutomationRuleEvaluatorPublic_SpanLlmAsJudge(Base):
    type: typing.Literal["span_llm_as_judge"] = "span_llm_as_judge"
    filters: typing.Optional[typing.List[SpanFilterPublic]] = None
    code: typing.Optional[SpanLlmAsJudgeCodePublic] = 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


class AutomationRuleEvaluatorPublic_SpanUserDefinedMetricPython(Base):
    type: typing.Literal["span_user_defined_metric_python"] = "span_user_defined_metric_python"
    filters: typing.Optional[typing.List[SpanFilterPublic]] = None
    code: typing.Optional[SpanUserDefinedMetricPythonCodePublic] = 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


AutomationRuleEvaluatorPublic = typing.Union[
    AutomationRuleEvaluatorPublic_LlmAsJudge,
    AutomationRuleEvaluatorPublic_UserDefinedMetricPython,
    AutomationRuleEvaluatorPublic_TraceThreadLlmAsJudge,
    AutomationRuleEvaluatorPublic_TraceThreadUserDefinedMetricPython,
    AutomationRuleEvaluatorPublic_SpanLlmAsJudge,
    AutomationRuleEvaluatorPublic_SpanUserDefinedMetricPython,
]
