import { z } from 'zod'
import { CODE_REGEX, MAX_CODE_LENGTH } from '@/lib/code'

const codeField = z
  .string()
  .trim()
  .max(MAX_CODE_LENGTH)
  .regex(CODE_REGEX, 'Ongeldige code')
  .optional()
  .or(z.literal(''))
const statusField = z.enum(['ready', 'blocked', 'done']).optional()

export const createPbiSchema = z.object({
  productId: z.string(),
  code: codeField,
  title: z.string().min(1, 'Titel is verplicht').max(200),
  description: z.string().max(2000).optional(),
  priority: z.coerce.number().int().min(1).max(4),
  status: statusField,
})

export const updatePbiSchema = z.object({
  id: z.string(),
  code: codeField,
  title: z.string().min(1, 'Titel is verplicht').max(200),
  description: z.string().max(2000).optional(),
  priority: z.coerce.number().int().min(1).max(4),
  status: statusField,
})

export type CreatePbiInput = z.infer<typeof createPbiSchema>
export type UpdatePbiInput = z.infer<typeof updatePbiSchema>
