import { z } from 'zod';

/** Accepts `09xxxxxxxx` or `+2519xxxxxxxx`; always yields `+2519xxxxxxxx`. */
export const ethiopianPhone = z
  .string()
  .trim()
  .transform((v) => (/^09\d{8}$/.test(v) ? `+251${v.slice(1)}` : v))
  .refine((v) => /^\+2519\d{8}$/.test(v), {
    message: 'Enter a valid phone number (+2519xxxxxxxx)',
  });

/** Same rules, but blank is allowed. */
export const optionalEthiopianPhone = z.union([z.literal(''), ethiopianPhone]).optional();
