import { z } from 'zod';

export const createChallengeSchema = z.object({
  title: z.string().min(1).max(200),
  description: z.string().max(2000).optional(),
  metric: z.enum([
    'DOORS_KNOCKED',
    'EMAILS_SENT',
    'SHIFTS_ATTENDED',
    'RESPONSES_SUBMITTED',
    'REFERRALS_MADE',
  ]),
  startsAt: z.string().datetime(),
  endsAt: z.string().datetime(),
  minTeamSize: z.number().int().min(1).max(50).default(2),
  maxTeamSize: z.number().int().min(2).max(100).default(10),
  maxTeams: z.number().int().min(1).optional(),
});

export const updateChallengeSchema = createChallengeSchema.partial();

export const createTeamSchema = z.object({
  name: z.string().min(1).max(100),
});

export const listChallengesSchema = z.object({
  page: z.coerce.number().int().min(1).default(1),
  limit: z.coerce.number().int().min(1).max(100).default(20),
  status: z
    .enum(['DRAFT', 'UPCOMING', 'ACTIVE', 'COMPLETED', 'CANCELLED'])
    .optional(),
});

export type CreateChallengeInput = z.infer<typeof createChallengeSchema>;
export type UpdateChallengeInput = z.infer<typeof updateChallengeSchema>;
export type CreateTeamInput = z.infer<typeof createTeamSchema>;
export type ListChallengesInput = z.infer<typeof listChallengesSchema>;
