import { z } from 'zod';
import { baseListQuerySchema } from '@/lib/api/list-query';

export const createReminderSchema = z.object({
  title: z.string().min(1).max(300),
  note: z.string().max(2000).optional(),
  dueAt: z.string().datetime(),
  priority: z.enum(['low', 'medium', 'high', 'urgent']).default('medium'),
  assignedTo: z.string().optional(),
  clientId: z.string().uuid().optional(),
  interestId: z.string().uuid().optional(),
  berthId: z.string().uuid().optional(),
  // Phase 4: yacht-linked reminders.
  yachtId: z.string().uuid().optional(),
});

export type CreateReminderInput = z.infer<typeof createReminderSchema>;

export const updateReminderSchema = z.object({
  title: z.string().min(1).max(300).optional(),
  note: z.string().max(2000).nullable().optional(),
  dueAt: z.string().datetime().optional(),
  priority: z.enum(['low', 'medium', 'high', 'urgent']).optional(),
  assignedTo: z.string().nullable().optional(),
  clientId: z.string().uuid().nullable().optional(),
  interestId: z.string().uuid().nullable().optional(),
  berthId: z.string().uuid().nullable().optional(),
  yachtId: z.string().uuid().nullable().optional(),
});

export type UpdateReminderInput = z.infer<typeof updateReminderSchema>;

export const snoozeReminderSchema = z.object({
  snoozeUntil: z.string().datetime(),
});

export type SnoozeReminderInput = z.infer<typeof snoozeReminderSchema>;

export const reminderListQuerySchema = baseListQuerySchema.extend({
  status: z.enum(['pending', 'snoozed', 'completed', 'dismissed']).optional(),
  priority: z.enum(['low', 'medium', 'high', 'urgent']).optional(),
  assignedTo: z.string().optional(),
  clientId: z.string().uuid().optional(),
  interestId: z.string().uuid().optional(),
  berthId: z.string().uuid().optional(),
  yachtId: z.string().uuid().optional(),
  dueBefore: z.string().datetime().optional(),
  dueAfter: z.string().datetime().optional(),
});

export type ReminderListQuery = z.infer<typeof reminderListQuerySchema>;
