import { z } from 'zod';

export const MAX_USER_MESSAGE_LENGTH = 2000;

export interface UserMessageFormValues {
  email: string;
  message: string;
}

/** Translator shape compatible with next-intl's `useTranslations` return value. */
type Translator = (key: string, values?: Record<string, string | number>) => string;

/**
 * Builds the contribute-form schema with localized messages.
 * Pass a translator scoped to the `contribute.validation` namespace.
 */
export function createUserMessageFormSchema(t: Translator) {
  return z.object({
    email: z.string().min(1, t('emailRequired')).email(t('emailInvalid')),
    message: z
      .string()
      .min(1, t('messageRequired'))
      .max(MAX_USER_MESSAGE_LENGTH, t('messageMax', { max: MAX_USER_MESSAGE_LENGTH })),
  });
}
