# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import Dict, List, Union, Optional
from typing_extensions import Literal, TypeAlias

from .._models import BaseModel

__all__ = [
    "CampaignGetRowsResponse",
    "Row",
    "RowCall",
    "RowCallAssistant",
    "RowCallAssistantCalendly",
    "RowCallAssistantCallRetryConfig",
    "RowCallAssistantCallRetryConfigCallingWindow",
    "RowCallAssistantLlmModel",
    "RowCallAssistantLlmModelUnionMember0",
    "RowCallAssistantLlmModelUnionMember1",
    "RowCallAssistantStructuredOutputConfig",
    "RowCallAssistantVoice",
    "RowCallAssistantFaqItem",
    "RowCallCallAttempt",
    "RowCallCallAttemptTranscript",
    "RowCallCallRetryConfig",
    "RowCallCallRetryConfigCallingWindow",
    "RowCallCampaign",
    "RowCallLastCallAttempt",
    "RowCallLastCallAttemptTranscript",
    "RowCallLlmModel",
    "RowCallLlmModelUnionMember0",
    "RowCallLlmModelUnionMember1",
]


class RowCallAssistantCalendly(BaseModel):
    connection_id: str
    """
    The connection ID representing the link between your Calendly account and Revox.
    """

    event_type_id: str
    """The event type ID representing the event type to schedule.

    (eg: https://api.calendly.com/event_types/b2330295-2a91-4a1d-bb73-99e7707663d5)
    """


class RowCallAssistantCallRetryConfigCallingWindow(BaseModel):
    calling_window_end_time: str
    """
    End time for the calling window in the recipient's timezone (or
    timezone_override if provided). Format: 'HH:mm' (24-hour) or 'H:mma' (12-hour).
    Examples: '17:00', '6pm'. Default: '18:00'.
    """

    calling_window_start_time: str
    """
    Start time for the calling window in the recipient's timezone (or
    timezone_override if provided). Format: 'HH:mm' (24-hour) or 'H:mma' (12-hour).
    Examples: '09:00', '10am'. Default: '10:00'.
    """

    retry_delay_seconds: int
    """Delay between retry attempts in seconds. Default: 7200 (2 hours)."""


class RowCallAssistantCallRetryConfig(BaseModel):
    """
    Configuration for call retry behavior including time windows, delays, and max iterations. If not provided, defaults will be used.
    """

    calling_windows: List[RowCallAssistantCallRetryConfigCallingWindow]

    max_retry_attempts: int
    """Maximum number of call retry attempts. Default: 3."""

    timezone: Optional[str] = None
    """
    Optional IANA timezone identifier to override the automatic timezone detection
    from phone number. If not provided, timezone is determined from the recipient's
    phone number country code. Examples: 'America/New_York', 'Europe/Paris'.
    """


class RowCallAssistantLlmModelUnionMember0(BaseModel):
    name: Literal["gpt-4.1", "ministral-3-8b-instruct"]

    type: Literal["dedicated-instance"]


class RowCallAssistantLlmModelUnionMember1(BaseModel):
    openrouter_model_id: str
    """The model ID to use from OpenRouter. eg: openai/gpt-4.1"""

    openrouter_provider: str
    """The provider to use from OpenRouter. eg: nebius, openai, azure, etc."""

    type: Literal["openrouter"]
    """Use a model from OpenRouter."""


RowCallAssistantLlmModel: TypeAlias = Union[RowCallAssistantLlmModelUnionMember0, RowCallAssistantLlmModelUnionMember1]


class RowCallAssistantStructuredOutputConfig(BaseModel):
    name: str

    required: bool

    type: Literal["string", "number", "boolean", "enum", "date", "datetime"]

    description: Optional[str] = None

    enum_options: Optional[List[str]] = None


class RowCallAssistantVoice(BaseModel):
    id: str
    """The ID of the voice."""

    provider: Literal["cartesia", "elevenlabs"]
    """The provider of the voice."""

    speed: Optional[float] = None
    """The speed of the voice.

    Range depends on provider: Cartesia 0.6–1.5, ElevenLabs 0.7–1.2. Default is 1.0.
    """


class RowCallAssistantFaqItem(BaseModel):
    answer: str

    question: str

    id: Optional[str] = None

    needs_human_answer: Optional[bool] = None

    source: Optional[Literal["human", "ai"]] = None


class RowCallAssistant(BaseModel):
    id: str

    background_sound: Optional[Literal["audio/office.ogg"]] = None
    """The background sound to play during the call.

    Useful to give the impression that your AI agent is in an office.
    """

    calendly: Optional[RowCallAssistantCalendly] = None

    call_retry_config: Optional[RowCallAssistantCallRetryConfig] = None
    """
    Configuration for call retry behavior including time windows, delays, and max
    iterations. If not provided, defaults will be used.
    """

    created_at: object

    end_of_call_sentence: Optional[str] = None

    first_sentence: Optional[str] = None

    first_sentence_delay_ms: int
    """Delay in milliseconds before speaking the first sentence. Default: 400."""

    first_sentence_mode: Literal["generated", "static", "none"]

    ivr_navigation_enabled: bool
    """Enable IVR navigation tools.

    When enabled, the assistant can send DTMF tones and skip turns to navigate phone
    menus.
    """

    llm_model: RowCallAssistantLlmModel

    max_call_duration_secs: float
    """The maximum duration of the call in seconds.

    This is the maximum time the call will be allowed to run.
    """

    name: str

    organization_id: str

    prompt: str

    structured_output_config: Optional[List[RowCallAssistantStructuredOutputConfig]] = None
    """The structured output config to use for the call.

    This is used to extract the data from the call (like email, name, company name,
    etc.).
    """

    transfer_phone_number: Optional[str] = None
    """Phone number to transfer calls to when users request to speak to a human agent."""

    updated_at: object

    voice: Optional[RowCallAssistantVoice] = None

    voicemail_message: Optional[str] = None
    """
    If set, when voicemail is detected the agent will speak this message then hang
    up; if null, hang up immediately.
    """

    webhook_url: Optional[str] = None
    """The webhook URL to call when the call is completed."""

    faq_items: Optional[List[RowCallAssistantFaqItem]] = None

    pending_faq_count: Optional[float] = None


class RowCallCallAttemptTranscript(BaseModel):
    content: str

    role: Literal["user", "assistant", "tool"]

    tool_arguments: Union[Dict[str, object], str, None] = None

    tool_is_error: Optional[bool] = None

    tool_name: Optional[str] = None


class RowCallCallAttempt(BaseModel):
    """This represent a single call attempt.

    A call attempt is a single call made to the phone number.
    """

    id: str
    """The ID of the call attempt."""

    answered_at: object
    """The time the call was answered."""

    dial_error: Optional[
        Literal[
            "number_non_attributed",
            "too_many_calls",
            "busy",
            "temporarily_unavailable",
            "no_answer",
            "no_international_permission",
            "precondition_failed",
            "non_classified_error",
        ]
    ] = None
    """The SIP error that occurred."""

    ended_at: object
    """The time the call ended."""

    phone_number: str
    """The phone number that was called.

    Formatted in E.164 format. Example: +1234567890
    """

    recording_url: Optional[str] = None
    """The URL of the audio recording of the call."""

    result: Optional[Literal["IVR", "voicemail", "human", "unknown", "ios-screening-filter"]] = None

    started_at: object
    """The time the call started."""

    status: Literal["queued", "ringing", "ongoing", "completed", "error"]
    """The status of the call attempt."""

    end_reason: Optional[str] = None
    """Reason for ending the call when ended_by is 'agent'.

    E.g. 'tool_end_call', 'voicemail', 'transfer', 'ivr_no_navigate'.
    """

    ended_by: Optional[Literal["agent", "user", "system"]] = None
    """
    Who ended the call: 'agent' (AI agent), 'user' (caller/callee hung up), or
    'system' (e.g. max duration limit).
    """

    structured_output: Optional[Dict[str, object]] = None
    """
    The data extracted from the call, using the structured output config from the
    parent call object.
    """

    transcript: Optional[List[RowCallCallAttemptTranscript]] = None
    """The transcript of the call."""


class RowCallCallRetryConfigCallingWindow(BaseModel):
    calling_window_end_time: str
    """
    End time for the calling window in the recipient's timezone (or
    timezone_override if provided). Format: 'HH:mm' (24-hour) or 'H:mma' (12-hour).
    Examples: '17:00', '6pm'. Default: '18:00'.
    """

    calling_window_start_time: str
    """
    Start time for the calling window in the recipient's timezone (or
    timezone_override if provided). Format: 'HH:mm' (24-hour) or 'H:mma' (12-hour).
    Examples: '09:00', '10am'. Default: '10:00'.
    """

    retry_delay_seconds: int
    """Delay between retry attempts in seconds. Default: 7200 (2 hours)."""


class RowCallCallRetryConfig(BaseModel):
    """
    Configuration for call retry behavior including time windows, delays, and max iterations. If not provided, defaults will be used.
    """

    calling_windows: List[RowCallCallRetryConfigCallingWindow]

    max_retry_attempts: int
    """Maximum number of call retry attempts. Default: 3."""

    timezone: Optional[str] = None
    """
    Optional IANA timezone identifier to override the automatic timezone detection
    from phone number. If not provided, timezone is determined from the recipient's
    phone number country code. Examples: 'America/New_York', 'Europe/Paris'.
    """


class RowCallCampaign(BaseModel):
    id: str

    name: str


class RowCallLastCallAttemptTranscript(BaseModel):
    content: str

    role: Literal["user", "assistant", "tool"]

    tool_arguments: Union[Dict[str, object], str, None] = None

    tool_is_error: Optional[bool] = None

    tool_name: Optional[str] = None


class RowCallLastCallAttempt(BaseModel):
    """This represent a single call attempt.

    A call attempt is a single call made to the phone number.
    """

    id: str
    """The ID of the call attempt."""

    answered_at: object
    """The time the call was answered."""

    dial_error: Optional[
        Literal[
            "number_non_attributed",
            "too_many_calls",
            "busy",
            "temporarily_unavailable",
            "no_answer",
            "no_international_permission",
            "precondition_failed",
            "non_classified_error",
        ]
    ] = None
    """The SIP error that occurred."""

    ended_at: object
    """The time the call ended."""

    phone_number: str
    """The phone number that was called.

    Formatted in E.164 format. Example: +1234567890
    """

    recording_url: Optional[str] = None
    """The URL of the audio recording of the call."""

    result: Optional[Literal["IVR", "voicemail", "human", "unknown", "ios-screening-filter"]] = None

    started_at: object
    """The time the call started."""

    status: Literal["queued", "ringing", "ongoing", "completed", "error"]
    """The status of the call attempt."""

    end_reason: Optional[str] = None
    """Reason for ending the call when ended_by is 'agent'.

    E.g. 'tool_end_call', 'voicemail', 'transfer', 'ivr_no_navigate'.
    """

    ended_by: Optional[Literal["agent", "user", "system"]] = None
    """
    Who ended the call: 'agent' (AI agent), 'user' (caller/callee hung up), or
    'system' (e.g. max duration limit).
    """

    structured_output: Optional[Dict[str, object]] = None
    """
    The data extracted from the call, using the structured output config from the
    parent call object.
    """

    transcript: Optional[List[RowCallLastCallAttemptTranscript]] = None
    """The transcript of the call."""


class RowCallLlmModelUnionMember0(BaseModel):
    name: Literal["gpt-4.1", "ministral-3-8b-instruct"]

    type: Literal["dedicated-instance"]


class RowCallLlmModelUnionMember1(BaseModel):
    openrouter_model_id: str
    """The model ID to use from OpenRouter. eg: openai/gpt-4.1"""

    openrouter_provider: str
    """The provider to use from OpenRouter. eg: nebius, openai, azure, etc."""

    type: Literal["openrouter"]
    """Use a model from OpenRouter."""


RowCallLlmModel: TypeAlias = Union[RowCallLlmModelUnionMember0, RowCallLlmModelUnionMember1]


class RowCall(BaseModel):
    """This represent a call "order" that was requested by the user.

    A call order can be resolved over multiple call attempts spanning up to a few days.
    """

    id: str
    """The ID of the call."""

    assistant: Optional[RowCallAssistant] = None

    call_attempts: List[RowCallCallAttempt]
    """All call attempts for this call order, ordered by most recent first."""

    call_retry_config: Optional[RowCallCallRetryConfig] = None
    """
    Configuration for call retry behavior including time windows, delays, and max
    iterations. If not provided, defaults will be used.
    """

    calls_count: float
    """The number of call attempts made."""

    campaign: Optional[RowCallCampaign] = None

    created_at: object
    """The time the call order was created."""

    direction: Literal["inbound", "outbound"]
    """Whether the call is inbound or outbound."""

    first_sentence_delay_ms: int
    """Delay in milliseconds before speaking the first sentence. Default: 400."""

    from_phone_number: str
    """The phone number that made the call.

    Formatted in E.164 format. Example: +1234567890
    """

    is_cancelled: bool
    """DEPRECATED: Whether the call has been cancelled.

    This is derived from `status`. Use `status` instead.
    """

    is_completed: bool
    """DEPRECATED: Whether the call has completed.

    This is derived from `status`. Use `status` instead.
    """

    last_call_attempt: Optional[RowCallLastCallAttempt] = None
    """This represent a single call attempt.

    A call attempt is a single call made to the phone number.
    """

    llm_model: RowCallLlmModel

    metadata: Optional[Dict[str, str]] = None
    """Metadata stored with the call."""

    organization_id: str
    """The ID of the organization that owns the call."""

    scheduled_at: object
    """The time the call order is scheduled to start."""

    status: Literal["initializing", "queued_for_calling", "calling", "scheduled", "completed", "cancelled", "errored"]
    """The status of the call."""

    to_phone_number: str
    """The phone number that received the call.

    Formatted in E.164 format. Example: +1234567890
    """


class Row(BaseModel):
    id: str

    input_data: Dict[str, str]

    phone_number: str

    row_index: float

    call: Optional[RowCall] = None
    """This represent a call "order" that was requested by the user.

    A call order can be resolved over multiple call attempts spanning up to a few
    days.
    """


class CampaignGetRowsResponse(BaseModel):
    page: float

    page_size: float

    rows: List[Row]

    total: float
