import { z } from 'zod'

/**
 * Generic API validation schemas for the external execution API surface.
 *
 * These schemas are ENVELOPE-ONLY -- they validate the transport layer
 * shape (resourceId, input, querystring params). They do NOT validate
 * per-workflow input shapes; that remains the responsibility of each
 * workflow's own contract.inputSchema.
 *
 * Multi-Tenant Layering Rule: apps/api stays generic. No per-workflow
 * shapes enter this file.
 */

/**
 * POST /execute-async - Request body envelope
 *
 * Validates that resourceId is present and non-empty.
 * `input` is accepted as unknown (opaque JSONB) -- per-workflow validation
 * is the workflow's own responsibility.
 */
export const ExecuteAsyncEnvelopeSchema = z.object({
  resourceId: z.string().min(1),
  input: z.unknown().optional()
})

export type ExecuteAsyncEnvelope = z.infer<typeof ExecuteAsyncEnvelopeSchema>

/**
 * GET /executions/:resourceId - Querystring parameters
 *
 * `limit`: max 100 rows per request to prevent excessive data transfer.
 * `status`: optional filter by execution status string.
 */
export const GetExecutionsQuerySchema = z.object({
  limit: z.coerce.number().int().min(1).max(100).default(50),
  status: z.string().optional()
})

export type GetExecutionsQuery = z.infer<typeof GetExecutionsQuerySchema>
