import { z } from "zod";
export const interests = [
  "Personal Loan",
  "Business Loan",
  "Foreigner Loan",
  "Payday Loan",
  "Debt Consolidation Plan",
  "Home Renovation Loan",
] as const;
const singleLine = z
  .string()
  .trim()
  .min(1, "This field is required.")
  .refine((value) => !/[\r\n\u0000]/.test(value), "Use a single line.");
export const enquirySchema = z.object({
  name: singleLine.max(100, "Use no more than 100 characters."),
  email: z
    .string()
    .trim()
    .max(254)
    .pipe(z.email("Enter a valid email address.")),
  phone: z
    .string()
    .trim()
    .max(30)
    .transform((value) => value.replace(/[\s()-]/g, ""))
    .pipe(
      z
        .string()
        .regex(
          /^\+?[1-9]\d{6,14}$/,
          "Enter a valid contact number, including country code if outside Singapore.",
        ),
    ),
  subject: singleLine.max(160, "Use no more than 160 characters."),
  interest: z.enum(interests, "Choose a loan type."),
  message: z
    .string()
    .trim()
    .min(10, "Please provide at least 10 characters.")
    .max(3000, "Use no more than 3,000 characters.")
    .refine(
      (value) => !value.includes("\u0000"),
      "Remove unsupported characters.",
    ),
});
export const contactRequestSchema = enquirySchema
  .extend({
    website: z.string().max(2048).optional().default(""),
    turnstileToken: z.string().min(1).max(2048),
    requestId: z.uuid(),
  })
  .strict();
export const contactResponseSchema = z.object({
  ok: z.boolean(),
  message: z.string(),
  mock: z.boolean().optional(),
});
export type Enquiry = z.output<typeof enquirySchema>;
export const enquiryActions = ["contact", "quick-apply"] as const;
export type EnquiryAction = (typeof enquiryActions)[number];
