import { z } from 'zod' import { convertPersianToEnglish } from '@/helpers' import { texts } from '@/texts' const toEnglishDigits = (value: string) => convertPersianToEnglish(value).trim() const v = texts.validation.identity const nationalId = texts.validation.nationalId export const IdentityVerificationFormValidation = z .object({ nationalCode: z .string() .min(1, nationalId.nationalCodeRequired) .refine((value) => /^\d{10}$/.test(toEnglishDigits(value)), { message: nationalId.nationalCodeDigits, }), contractAccepted: z.boolean().optional(), }) .superRefine((values, ctx) => { if (values.contractAccepted !== true) { ctx.addIssue({ code: 'custom', path: ['contractAccepted'], message: v.contractRequired, }) } }) export const IdentityContractOtpValidation = z.object({ code: z .string() .min(1, v.otpRequired) .refine((value) => /^\d{4}$/.test(toEnglishDigits(value)), { message: v.otpDigits, }), }) export type IdentityVerificationFormValues = z.infer export type IdentityContractOtpValues = z.infer export const normalizeNationalCode = (value: string) => toEnglishDigits(value) export const normalizeOtpCode = (value: string) => toEnglishDigits(value)