export type Phone = { ok: true; e164: string } | { ok: false; code: string; message: string };
/** Ethiopian mobile numbers (09 and 07). Excel's 9.11E+08 is refused, never guessed. */
export function parsePhone(raw: string): Phone {
  const s = raw.trim();
  if (!s) return { ok: false, code: "REQUIRED", message: "Enter a phone number." };
  if (/^[+-]?\d+(\.\d+)?e[+-]?\d+$/i.test(s)) return { ok: false, code: "PHONE_SCIENTIFIC_NOTATION", message: "This is an Excel number, not a phone number. Format the column as text." };
  const d = s.replace(/\.0$/, "").replace(/[\s().-]/g, "").replace(/^\+/, "").replace(/^251/, "").replace(/^0/, "");
  return /^[79]\d{8}$/.test(d) ? { ok: true, e164: `+251${d}` } : { ok: false, code: "PHONE_INVALID", message: "Use 10 digits starting with 09 or 07." };
}
export const showPhone = (e164: string | null): string => (e164 ? `0${e164.slice(4)}` : "");
