import { z } from 'zod';
import { TrackPointEvent } from '@prisma/client';

export const startTrackingSchema = z.object({
  canvassSessionId: z.string().optional(),
  latitude: z.number().min(-90).max(90).optional(),
  longitude: z.number().min(-180).max(180).optional(),
});

export const submitPointsSchema = z.object({
  points: z
    .array(
      z.object({
        latitude: z.number().min(-90).max(90),
        longitude: z.number().min(-180).max(180),
        accuracy: z.number().positive().optional(),
        recordedAt: z.string().datetime(),
        eventType: z.nativeEnum(TrackPointEvent).optional(),
      }),
    )
    .min(1)
    .max(100),
});

export const linkCanvassSchema = z.object({
  canvassSessionId: z.string().min(1),
});

export const liveVolunteersQuerySchema = z.object({
  staleCutoffMinutes: z.coerce.number().int().positive().default(10),
});

export const historicalListQuerySchema = z.object({
  userId: z.string().optional(),
  from: z.string().datetime().optional(),
  to: z.string().datetime().optional(),
  page: z.coerce.number().int().positive().default(1),
  limit: z.coerce.number().int().positive().max(100).default(20),
});

export const myHistoricalListQuerySchema = z.object({
  from: z.string().datetime().optional(),
  to: z.string().datetime().optional(),
  page: z.coerce.number().int().positive().default(1),
  limit: z.coerce.number().int().positive().max(100).default(15),
});

export type StartTrackingInput = z.infer<typeof startTrackingSchema>;
export type SubmitPointsInput = z.infer<typeof submitPointsSchema>;
export type LinkCanvassInput = z.infer<typeof linkCanvassSchema>;
export type LiveVolunteersQueryInput = z.infer<typeof liveVolunteersQuerySchema>;
export type HistoricalListQueryInput = z.infer<typeof historicalListQuerySchema>;
export type MyHistoricalListQueryInput = z.infer<typeof myHistoricalListQuerySchema>;
