/**
 * Street Address Validation Utilities
 *
 * Validates Japanese street address format (chome-ban-go system).
 */

/**
 * Validates Japanese street address format (chome-ban-go system).
 *
 * Valid patterns:
 * - "1-2-3" (chome-banchi-go)
 * - "1-2" (chome-banchi)
 * - "12-34-5" (larger numbers)
 * - "1" (single number for some rural areas)
 *
 * Requirements:
 * - Must start with a number
 * - Can contain numbers separated by hyphens
 * - Minimum 1 digit required
 */
export function isValidStreetAddress(value: string): boolean {
  const trimmed = value.trim();
  if (!trimmed) return false;

  // Pattern: starts with digit(s), optionally followed by hyphen-digit groups
  // Examples: "1", "1-2", "1-2-3", "12-34-5"
  const pattern = /^\d+(-\d+)*$/;
  return pattern.test(trimmed);
}

/**
 * Returns validation error message for street address.
 * Returns undefined if valid.
 */
export function getStreetAddressError(value: string): string | undefined {
  const trimmed = value.trim();
  if (!trimmed) return "Street address is required";
  if (!isValidStreetAddress(trimmed)) {
    return "Enter a valid format (e.g., 1-2-3)";
  }
  return undefined;
}
