/**
 * Shared lead types — lead-lost-re-engagement (wave-14).
 *
 * Re-exported from @zync/types for use in both API routes and the SPA.
 */
import { z } from 'zod'

/**
 * Re-engagement window options.
 * `null` means "never re-engage" (no reengagement_at set).
 */
export type ReengagementWindow = 7 | 14 | 30 | 60 | 90 | null

export const REENGAGEMENT_WINDOWS: Array<{ value: ReengagementWindow; label: string }> = [
  { value: null, label: 'Never' },
  { value: 7,   label: 'In 7 days' },
  { value: 14,  label: 'In 14 days' },
  { value: 30,  label: 'In 30 days' },
  { value: 60,  label: 'In 60 days' },
  { value: 90,  label: 'In 90 days' },
]

/**
 * Body for PATCH /api/marketing/leads/:id when marking a lead as lost.
 * Extends the standard update with required stage=LOST + optional re-engagement.
 */
export const markLeadLostSchema = z.object({
  stage: z.literal('LOST'),
  lost_reason: z.string().max(1000).nullable().optional(),
  reengagement_at: z.string().datetime().nullable().optional(),
})

export type MarkLeadLostInput = z.infer<typeof markLeadLostSchema>

/**
 * Body for PATCH /api/marketing/leads/:id/reopen.
 * Moves the lead back to NEW, clears lost fields.
 */
export const reopenLeadSchema = z.object({
  stage: z.enum(['NEW', 'CONTACTED', 'QUALIFIED', 'PROPOSAL']).optional(),
})

export type ReopenLeadInput = z.infer<typeof reopenLeadSchema>
