import { z } from "zod/v4";
import { Uuid } from "./domain.js";

/**
 * dp-worker lifecycle deploy / restart / stop contracts (M-X wave 2 Agent A).
 *
 * The UI button hits dp-center-worker; dp-center-worker RPCs the DirectorConnection DO,
 * which forwards a `spawn_worker` / `restart_worker` / `stop_worker` envelope
 * (defined in ws-protocol.ts) over the hibernating WS to the dp-director. The
 * dp-director's `worker_state_change` flows back asynchronously — the REST call
 * just confirms the envelope was queued for delivery.
 *
 * Request bodies are intentionally thin: the WS envelope is assembled
 * server-side from the dp-worker row (api_key, director_id, …) so callers never
 * see the api_key in the wire path.
 */

/** No body. The deploy envelope is constructed entirely server-side. */
export const DeployRequestSchema = z.object({});
export type DeployRequest = z.infer<typeof DeployRequestSchema>;

/** Same shape used by all three lifecycle endpoints on the 202 path. */
export const DeployResponseSchema = z.object({
  accepted: z.literal(true),
  envelope_id: Uuid,
  director_id: Uuid,
});
export type DeployResponse = z.infer<typeof DeployResponseSchema>;

/**
 * Optional `graceful` flag on stop. When `false` the dp-director SIGKILLs instead
 * of giving the dp-worker process its normal SIGTERM grace window. Defaults to
 * true (graceful) when the body is omitted.
 */
export const StopRequestSchema = z.object({
  graceful: z.boolean().optional(),
});
export type StopRequest = z.infer<typeof StopRequestSchema>;
