/**
 * Zod validation schemas for task-dependency routes — task-dependencies.
 *
 * Used by:
 *   POST   /api/tasks/:id/dependencies         — createDependencySchema
 *   DELETE /api/tasks/:id/dependencies/:depId  — dependencyIdParamSchema
 */
import { z } from 'zod'

/**
 * Body for creating a dependency edge relative to `:id`.
 *
 * Supply exactly ONE of the two fields:
 *  - blocking_task_id → the supplied task blocks `:id`  (edge: supplied → :id)
 *  - blocked_task_id  → `:id` blocks the supplied task  (edge: :id → supplied)
 */
export const createDependencySchema = z
  .object({
    blocking_task_id: z.string().uuid().optional(),
    blocked_task_id: z.string().uuid().optional(),
  })
  .refine(
    (v) => Boolean(v.blocking_task_id) !== Boolean(v.blocked_task_id),
    { message: 'Supply exactly one of blocking_task_id or blocked_task_id' },
  )

export type CreateDependencyBody = z.infer<typeof createDependencySchema>

/** Path-param schema for the dependency id. */
export const dependencyIdParamSchema = z.object({
  dependencyId: z.string().uuid(),
})

export type DependencyIdParam = z.infer<typeof dependencyIdParamSchema>
