import { ScheduledTriggerInvocation } from "@inkeep/agents-core";

//#region src/domains/run/workflow/steps/scheduledTriggerSteps.d.ts

/**
 * Step: Log a message (allows logging from workflow context)
 */
declare function logStep(message: string, data: Record<string, unknown>): Promise<void>;
/**
 * Step: Calculate the next execution time relative to a base time.
 */
declare function calculateNextExecutionStep(params: {
  cronExpression?: string | null;
  cronTimezone?: string | null;
  runAt?: string | null;
  lastScheduledFor?: string | null;
}): Promise<{
  nextExecutionTime: string;
  isOneTime: boolean;
}>;
/**
 * Step: Compute sleep duration
 * Returns milliseconds to sleep.
 */
declare function computeSleepDurationStep(targetTime: string): Promise<number>;
/**
 * Step: Get the next pending invocation to execute (earliest scheduledFor).
 * Returns null if no pending invocations exist.
 */
declare function getNextPendingInvocationStep(params: {
  tenantId: string;
  projectId: string;
  agentId: string;
  scheduledTriggerId: string;
}): Promise<ScheduledTriggerInvocation | null>;
/**
 * Step: Delete all pending invocations for a trigger.
 * Used when cron expression changes or trigger is disabled.
 */
declare function deletePendingInvocationsStep(params: {
  tenantId: string;
  projectId: string;
  agentId: string;
  scheduledTriggerId: string;
}): Promise<number>;
/**
 * Step: Check if trigger is still enabled and this runner is authoritative.
 */
declare function checkTriggerEnabledStep(params: {
  tenantId: string;
  projectId: string;
  agentId: string;
  scheduledTriggerId: string;
  runnerId: string;
}): Promise<{
  shouldContinue: boolean;
  reason: string;
  trigger: null;
} | {
  shouldContinue: boolean;
  trigger: {
    createdAt: string;
    updatedAt: string;
    enabled: boolean;
    cronExpression: string | null;
    cronTimezone: string | null;
    runAt: string | null;
    messageTemplate: string | null;
    maxRetries: number;
    retryDelaySeconds: number;
    timeoutSeconds: number;
    runAsUserId: string | null;
    name: string;
    description: string | null;
    agentId: string;
    projectId: string;
    tenantId: string;
    id: string;
    createdBy: string | null;
    payload?: Record<string, unknown> | null | undefined;
  };
  reason?: undefined;
}>;
/**
 * Step: Try to create invocation idempotently.
 * Returns existing invocation if already created.
 */
declare function createInvocationIdempotentStep(params: {
  tenantId: string;
  projectId: string;
  agentId: string;
  scheduledTriggerId: string;
  scheduledFor: string;
  payload: Record<string, unknown> | null;
  idempotencyKey: string;
}): Promise<{
  invocation: {
    scheduledTriggerId: string;
    scheduledFor: string;
    startedAt: string | null;
    completedAt: string | null;
    conversationIds: string[] | null;
    attemptNumber: number;
    idempotencyKey: string;
    createdAt: string;
    agentId: string;
    projectId: string;
    tenantId: string;
    id: string;
    status: "pending" | "completed" | "running" | "failed" | "cancelled";
    resolvedPayload?: Record<string, unknown> | null | undefined;
  };
  alreadyExists: boolean;
}>;
/**
 * Step: Check if invocation was cancelled before execution
 * Returns true if cancelled (should skip execution), false otherwise
 */
declare function checkInvocationCancelledStep(params: {
  tenantId: string;
  projectId: string;
  agentId: string;
  scheduledTriggerId: string;
  invocationId: string;
}): Promise<{
  cancelled: boolean;
}>;
/**
 * Step: Mark invocation as running
 */
declare function markRunningStep(params: {
  tenantId: string;
  projectId: string;
  agentId: string;
  scheduledTriggerId: string;
  invocationId: string;
}): Promise<{
  scheduledTriggerId: string;
  scheduledFor: string;
  startedAt: string | null;
  completedAt: string | null;
  conversationIds: string[] | null;
  attemptNumber: number;
  idempotencyKey: string;
  createdAt: string;
  agentId: string;
  projectId: string;
  tenantId: string;
  id: string;
  status: "pending" | "completed" | "running" | "failed" | "cancelled";
  resolvedPayload?: Record<string, unknown> | null | undefined;
}>;
/**
 * Step: Add a conversation ID to the invocation's conversationIds array
 * Called after each attempt to track all conversations created during retries
 */
declare function addConversationIdStep(params: {
  tenantId: string;
  projectId: string;
  agentId: string;
  scheduledTriggerId: string;
  invocationId: string;
  conversationId: string;
}): Promise<{
  scheduledTriggerId: string;
  scheduledFor: string;
  startedAt: string | null;
  completedAt: string | null;
  conversationIds: string[] | null;
  attemptNumber: number;
  idempotencyKey: string;
  createdAt: string;
  agentId: string;
  projectId: string;
  tenantId: string;
  id: string;
  status: "pending" | "completed" | "running" | "failed" | "cancelled";
  resolvedPayload?: Record<string, unknown> | null | undefined;
} | undefined>;
/**
 * Step: Mark invocation as completed
 */
declare function markCompletedStep(params: {
  tenantId: string;
  projectId: string;
  agentId: string;
  scheduledTriggerId: string;
  invocationId: string;
}): Promise<{
  scheduledTriggerId: string;
  scheduledFor: string;
  startedAt: string | null;
  completedAt: string | null;
  conversationIds: string[] | null;
  attemptNumber: number;
  idempotencyKey: string;
  createdAt: string;
  agentId: string;
  projectId: string;
  tenantId: string;
  id: string;
  status: "pending" | "completed" | "running" | "failed" | "cancelled";
  resolvedPayload?: Record<string, unknown> | null | undefined;
} | undefined>;
/**
 * Step: Mark invocation as failed
 */
declare function markFailedStep(params: {
  tenantId: string;
  projectId: string;
  agentId: string;
  scheduledTriggerId: string;
  invocationId: string;
}): Promise<{
  scheduledTriggerId: string;
  scheduledFor: string;
  startedAt: string | null;
  completedAt: string | null;
  conversationIds: string[] | null;
  attemptNumber: number;
  idempotencyKey: string;
  createdAt: string;
  agentId: string;
  projectId: string;
  tenantId: string;
  id: string;
  status: "pending" | "completed" | "running" | "failed" | "cancelled";
  resolvedPayload?: Record<string, unknown> | null | undefined;
} | undefined>;
/**
 * Step: Increment attempt number for retry
 */
declare function incrementAttemptStep(params: {
  tenantId: string;
  projectId: string;
  agentId: string;
  scheduledTriggerId: string;
  invocationId: string;
  currentAttempt: number;
}): Promise<void>;
/**
 * Step: Execute the scheduled trigger using executeAgentAsync.
 *
 * Uses the shared executeAgentAsync from TriggerService which includes
 * proper tracing, error handling, and conversation management.
 */
declare function executeScheduledTriggerStep(params: {
  tenantId: string;
  projectId: string;
  agentId: string;
  scheduledTriggerId: string;
  invocationId: string;
  messageTemplate?: string | null;
  payload?: Record<string, unknown> | null;
  timeoutSeconds: number;
  runAsUserId?: string | null;
}): Promise<{
  success: boolean;
  conversationId?: string;
  error?: string;
}>;
//#endregion
export { addConversationIdStep, calculateNextExecutionStep, checkInvocationCancelledStep, checkTriggerEnabledStep, computeSleepDurationStep, createInvocationIdempotentStep, deletePendingInvocationsStep, executeScheduledTriggerStep, getNextPendingInvocationStep, incrementAttemptStep, logStep, markCompletedStep, markFailedStep, markRunningStep };