import { z } from 'zod' import { convertPersianToEnglish } from '@/helpers' import { texts } from '@/texts' const v = texts.validation.withdrawal const nationalId = texts.validation.nationalId const toEnglishDigits = (value: string) => convertPersianToEnglish(value).trim() export const CreateBankAccountFormValidation = (requiresNationalCode: boolean) => z .object({ iban: z .string() .trim() .transform((value) => toEnglishDigits(value).toUpperCase().replace(/\s+/g, '')) .refine((value) => /^IR\d{24}$/.test(value), v.ibanInvalid), nationalCode: z.string().trim().transform((value) => toEnglishDigits(value)), }) .superRefine((value, ctx) => { if (!requiresNationalCode) return if (!value.nationalCode) { ctx.addIssue({ code: 'custom', path: ['nationalCode'], message: nationalId.nationalCodeRequired }) return } if (!/^\d{10}$/.test(value.nationalCode)) { ctx.addIssue({ code: 'custom', path: ['nationalCode'], message: nationalId.nationalCodeDigits }) } }) export type CreateBankAccountFormValues = z.infer> export const CreateWithdrawalRequestFormValidation = z.object({ bankAccountId: z.string().min(1, v.bankAccountRequired), amount: z .string() .trim() .min(1, v.amountRequired) .transform((value) => toEnglishDigits(value)) .refine((value) => /^\d+$/.test(value), v.amountInteger) .refine((value) => Number(value) > 0, v.amountPositive), }) export type CreateWithdrawalRequestFormValues = z.infer