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

import datetime as dt
import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2
from ..core.unchecked_base_model import UncheckedBaseModel
from .query_builder_request_group_by_item import QueryBuilderRequestGroupByItem
from .query_builder_request_sort_by import QueryBuilderRequestSortBy
from .query_builder_request_sort_direction import QueryBuilderRequestSortDirection
from .query_builder_request_tag_mode import QueryBuilderRequestTagMode


class QueryBuilderRequest(UncheckedBaseModel):
    """
    Request for building and executing queries using PulseQuery
    """

    limit: typing.Optional[int] = pydantic.Field(default=None)
    """
    Maximum results to return
    """

    offset: typing.Optional[int] = pydantic.Field(default=None)
    """
    Offset for pagination
    """

    text_query: typing.Optional[str] = pydantic.Field(default=None)
    """
    Text to search in descriptions
    """

    time_range_start: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    Start time for filtering
    """

    time_range_end: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    End time for filtering
    """

    last_hours: typing.Optional[int] = pydantic.Field(default=None)
    """
    Filter to last N hours
    """

    last_days: typing.Optional[int] = pydantic.Field(default=None)
    """
    Filter to last N days
    """

    agent_types: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Filter by agent types
    """

    agent_ids: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Filter by specific agent IDs
    """

    object_types: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Filter by object types
    """

    object_ids: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Filter by specific object IDs
    """

    action_types: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Filter by action types
    """

    action_statuses: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Filter by action statuses
    """

    specific_actions: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Filter by specific action names
    """

    tags: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Tags to include
    """

    exclude_tags: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Tags to exclude
    """

    tag_mode: typing.Optional[QueryBuilderRequestTagMode] = pydantic.Field(default=None)
    """
    Whether to match any or all tags
    """

    min_duration_minutes: typing.Optional[float] = pydantic.Field(default=None)
    """
    Minimum duration in minutes
    """

    max_duration_minutes: typing.Optional[float] = pydantic.Field(default=None)
    """
    Maximum duration in minutes
    """

    customer_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    Filter by customer ID
    """

    team_name: typing.Optional[str] = pydantic.Field(default=None)
    """
    Filter by team
    """

    deal_stages: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    Filter by deal stages
    """

    revenue_impact: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Filter for revenue impact events
    """

    churn_risk: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Filter for churn risk events
    """

    escalation_level: typing.Optional[str] = pydantic.Field(default=None)
    """
    Filter by escalation level
    """

    trace_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    Filter by trace ID
    """

    triggered_by: typing.Optional[str] = pydantic.Field(default=None)
    """
    Filter by triggering event
    """

    sort_by: typing.Optional[QueryBuilderRequestSortBy] = pydantic.Field(default=None)
    """
    Sort field
    """

    sort_direction: typing.Optional[QueryBuilderRequestSortDirection] = pydantic.Field(default=None)
    """
    Sort direction
    """

    count_only: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Return only count, not full results
    """

    explain: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Include query explanation
    """

    aggregate: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Return aggregated results
    """

    group_by: typing.Optional[typing.List[QueryBuilderRequestGroupByItem]] = pydantic.Field(default=None)
    """
    Group by fields for aggregation
    """

    group_by_tag_prefix: typing.Optional[str] = pydantic.Field(default=None)
    """
    Group by tag prefix (e.g., 'customer:')
    """

    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
