import { z } from "zod/v4";
import { TaskRunStatus, TaskSource, Uuid } from "./domain.js";
/**
 * History / cross-dp-worker listing contracts (M8 Phase A wave-1).
 *
 * Three new GET endpoints share these wire shapes:
 *   - GET /api/tasks/adhoc          AdhocBatchListItemSchema
 *   - GET /api/tasks/runs           TaskRunListItemSchema
 *   - GET /api/scheduled-tasks      ScheduledTaskListItemSchema
 *
 * Cursors are opaque strings (timestamp-based, but the client should NOT
 * parse them) — the server hands one back as `next_cursor` and the client
 * passes it through unchanged to fetch the next page.
 */
export const AdhocBatchListItemSchema = z.object({
    id: Uuid,
    name: z.string(),
    prompt: z.string(),
    target_descriptor_json: z.record(z.string(), z.unknown()),
    random_delay_seconds: z.number().int().nonnegative(),
    dispatch_window_seconds: z.number().int().nonnegative(),
    summary_stats_json: z.record(z.string(), z.unknown()).optional(),
    created_by: Uuid.optional(),
    created_at: z.string().datetime(),
    /** Counts derived from joined task_runs.parent_adhoc_task_id. */
    run_count: z.number().int().nonnegative(),
    success_count: z.number().int().nonnegative(),
    failure_count: z.number().int().nonnegative(),
});
export const AdhocBatchListResponseSchema = z.object({
    items: z.array(AdhocBatchListItemSchema),
    next_cursor: z.string().optional(),
});
export const TaskRunListItemSchema = z.object({
    id: Uuid,
    worker_id: Uuid,
    worker_name: z.string(),
    task_name: z.string(),
    scheduled_task_id: Uuid.optional(),
    parent_adhoc_task_id: Uuid.optional(),
    source: TaskSource,
    status: TaskRunStatus,
    prompt: z.string(),
    dispatched_at: z.string().datetime().optional(),
    started_at: z.string().datetime().optional(),
    finished_at: z.string().datetime().optional(),
    result_summary: z.string().optional(),
    error: z.string().optional(),
    randomized_delay_ms: z.number().int().nonnegative(),
    scheduled_fire_at: z.string().datetime().optional(),
    created_at: z.string().datetime(),
});
export const TaskRunHistoryListResponseSchema = z.object({
    items: z.array(TaskRunListItemSchema),
    next_cursor: z.string().optional(),
});
/**
 * Cross-dp-worker scheduled-task row. Shape differs from the per-dp-worker
 * `ScheduledTaskResponseSchema` only in that it carries `worker_name`
 * (joined from dp_workers) — handy when listing across dp-workers.
 */
export const ScheduledTaskListItemSchema = z.object({
    id: Uuid,
    worker_id: Uuid,
    worker_name: z.string(),
    worker_status: z.string().optional(),
    name: z.string(),
    cron: z.string(),
    timezone: z.string().optional(),
    prompt: z.string(),
    random_delay_seconds: z.number().int().nonnegative(),
    enabled: z.boolean(),
    last_run_at: z.string().datetime().optional(),
    last_status: z.enum(["ok", "error"]).optional(),
    run_count: z.number().int().nonnegative(),
    success_count: z.number().int().nonnegative(),
    proxy_timezone: z.string().optional(),
    effective_timezone: z.string(),
    timezone_source: z.enum(["task", "proxy", "utc"]),
    next_fire_at: z.string().datetime().optional(),
    health_status: z.enum(["healthy", "failing", "never_run", "disabled"]),
    latest_run_id: Uuid.optional(),
    latest_run_status: z
        .enum([
        "queued",
        "dispatched",
        "running",
        "success",
        "failed",
        "cancelled",
        "timeout",
    ])
        .optional(),
    last_error: z.string().optional(),
    created_at: z.string().datetime(),
    updated_at: z.string().datetime(),
});
export const ScheduledTaskListResponseSchema = z.object({
    items: z.array(ScheduledTaskListItemSchema),
    next_cursor: z.string().optional(),
});
//# sourceMappingURL=task-history-contracts.js.map