const IRAN_MOBILE_PATTERN = /^9\d{9}$/;

/** Normalize Iranian mobile to sms.ir format (e.g. 9123456789). */
export function normalizeIranMobile(input: string): string {
  let digits = input.replace(/\D/g, '');

  if (digits.startsWith('98') && digits.length === 12) {
    digits = digits.slice(2);
  }

  if (digits.startsWith('0') && digits.length === 11) {
    digits = digits.slice(1);
  }

  return digits;
}

export function isValidIranMobile(input: string): boolean {
  return IRAN_MOBILE_PATTERN.test(normalizeIranMobile(input));
}
