/**
 * Schedule Management Tool Types
 *
 * Zod schemas for schedule management platform tools.
 * These tools enable agents to query, cancel, and delete task schedules.
 */

import { z } from 'zod'

// ============================================
// List Schedules
// ============================================

export const ListSchedulesInputSchema = z.object({
  /** Filter by target resource ID */
  targetResourceId: z.string().optional(),
  /** Filter by schedule status */
  status: z.string().optional(),
  /** JSONB containment filter for metadata (e.g., { contactEmail: 'user@example.com' }) */
  metadata: z.record(z.string(), z.unknown()).optional(),
  /** Maximum results to return (1-100, default: 20) */
  limit: z.number().min(1).max(100).default(20)
})

export const ListSchedulesOutputSchema = z.object({
  schedules: z.array(z.object({
    id: z.string(),
    name: z.string(),
    status: z.string(),
    nextRunAt: z.string().nullable(),
    idempotencyKey: z.string().nullable(),
    createdAt: z.string()
  })),
  total: z.number()
})

export type ListSchedulesInput = z.infer<typeof ListSchedulesInputSchema>
export type ListSchedulesOutput = z.infer<typeof ListSchedulesOutputSchema>

// ============================================
// Cancel Schedules by Metadata
// ============================================

export const CancelSchedulesByMetadataInputSchema = z.object({
  /** JSONB containment filter for metadata (required) */
  metadata: z.record(z.string(), z.unknown()),
  /** Only cancel schedules with this status (default: 'active') */
  status: z.string().default('active')
})

export const CancelSchedulesByMetadataOutputSchema = z.object({
  cancelled: z.number()
})

export type CancelSchedulesByMetadataInput = z.infer<typeof CancelSchedulesByMetadataInputSchema>
export type CancelSchedulesByMetadataOutput = z.infer<typeof CancelSchedulesByMetadataOutputSchema>

// ============================================
// Cancel Schedule by Idempotency Key
// ============================================

export const CancelScheduleByKeyInputSchema = z.object({
  /** Idempotency key of the schedule to cancel */
  idempotencyKey: z.string()
})

export const CancelScheduleByKeyOutputSchema = z.object({
  cancelled: z.boolean()
})

export type CancelScheduleByKeyInput = z.infer<typeof CancelScheduleByKeyInputSchema>
export type CancelScheduleByKeyOutput = z.infer<typeof CancelScheduleByKeyOutputSchema>

// ============================================
// Delete Schedule by Idempotency Key
// ============================================

export const DeleteScheduleByKeyInputSchema = z.object({
  /** Idempotency key of the schedule to hard-delete */
  idempotencyKey: z.string()
})

export const DeleteScheduleByKeyOutputSchema = z.object({
  deleted: z.boolean()
})

export type DeleteScheduleByKeyInput = z.infer<typeof DeleteScheduleByKeyInputSchema>
export type DeleteScheduleByKeyOutput = z.infer<typeof DeleteScheduleByKeyOutputSchema>
