import { z } from 'zod';
import { GovernmentLevel, ResponseType, ResponseStatus } from '@prisma/client';

export const submitResponseSchema = z.object({
  representativeName: z.string().min(1, 'Representative name is required').max(200),
  representativeLevel: z.nativeEnum(GovernmentLevel),
  responseType: z.nativeEnum(ResponseType),
  responseText: z.string().min(1, 'Response text is required').max(5000),
  representativeTitle: z.string().max(200).optional(),
  representativeEmail: z.string().email().optional(),
  userComment: z.string().max(1000).optional(),
  submittedByName: z.string().max(200).optional(),
  submittedByEmail: z.string().email().optional(),
  isAnonymous: z.boolean().optional().default(false),
  sendVerification: z.boolean().optional().default(false),
});

export const listPublicResponsesSchema = z.object({
  page: z.coerce.number().int().positive().default(1),
  limit: z.coerce.number().int().positive().max(100).default(20),
  sort: z.enum(['recent', 'upvotes', 'verified']).optional().default('recent'),
  level: z.nativeEnum(GovernmentLevel).optional(),
});

export const listAdminResponsesSchema = z.object({
  page: z.coerce.number().int().positive().default(1),
  limit: z.coerce.number().int().positive().max(100).default(20),
  status: z.nativeEnum(ResponseStatus).optional(),
  campaignId: z.string().optional(),
  search: z.string().optional(),
});

export const updateResponseStatusSchema = z.object({
  status: z.nativeEnum(ResponseStatus),
});

export type SubmitResponseInput = z.infer<typeof submitResponseSchema>;
export type ListPublicResponsesInput = z.infer<typeof listPublicResponsesSchema>;
export type ListAdminResponsesInput = z.infer<typeof listAdminResponsesSchema>;
export type UpdateResponseStatusInput = z.infer<typeof updateResponseStatusSchema>;
