import { z } from 'zod';

const timeHHMM = z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/);
const lat = z.number().min(-90).max(90);
const lng = z.number().min(-180).max(180);

export const allocateVolunteersSchema = z.object({
  userIds: z.array(z.number().int().positive()).min(1).max(50),
});

export const checkInSchema = z.object({
  latitude: lat.optional(),
  longitude: lng.optional(),
  accuracyMeters: z.number().int().min(0).max(100000).optional(),
  withoutGps: z.boolean().default(false),
});
export type CheckInInput = z.infer<typeof checkInSchema>;

export const checkOutSchema = z.object({
  latitude: lat.optional(),
  longitude: lng.optional(),
  accuracyMeters: z.number().int().min(0).max(100000).optional(),
  startTime: timeHHMM, // Either auto-filled from check-in or entered manually
  distanceKm: z.number().positive().max(200),
  notes: z.string().max(500).optional(),
});
export type CheckOutInput = z.infer<typeof checkOutSchema>;

export const approveDistanceSchema = z.object({
  approvedKm: z.number().positive().max(200),
  decision: z.enum(['approved', 'rejected']),
  remarks: z.string().max(500).optional(),
});
