import { ERROR_MESSAGES } from '../i18n/error-messages';

/**
 * Validation Message Formatter Utility
 * Provides centralized message formatting for validation errors
 * Uses messages from error-messages.ts with placeholder interpolation
 */
export class ValidationMessageFormatter {
  /**
   * Format a validation message with placeholders
   * @param messageKey - Key from ERROR_MESSAGES
   * @param params - Array of values to replace placeholders {0}, {1}, etc.
   * @returns Formatted error message
   */
  static format(messageKey: string, ...params: any[]): string {
    let message = ERROR_MESSAGES[messageKey] || messageKey;
    
    // Replace placeholders {0}, {1}, etc. with actual values
    params.forEach((param, index) => {
      const placeholderRegex = new RegExp(`\\{${index}\\}`, 'g');
      message = message.replace(placeholderRegex, String(param));
    });
    
    return message;
  }

  /**
   * Format field required message
   */
  static fieldRequired(label: string): string {
    return this.format('FIELD_REQUIRED', label);
  }

  /**
   * Format field empty message
   */
  static fieldEmpty(label: string): string {
    return this.format('FIELD_EMPTY', label);
  }

  /**
   * Format text too short message
   */
  static textTooShort(label: string, minLength: number): string {
    return this.format('TEXT_TOO_SHORT', label, minLength);
  }

  /**
   * Format text too long message
   */
  static textTooLong(label: string, maxLength: number): string {
    return this.format('TEXT_TOO_LONG', label, maxLength);
  }

  /**
   * Format text invalid format message
   */
  static textInvalidFormat(label: string): string {
    return this.format('TEXT_INVALID_FORMAT', label);
  }

  /**
   * Format number invalid message
   */
  static numberInvalid(label: string): string {
    return this.format('NUMBER_INVALID', label);
  }

  /**
   * Format number too small message
   */
  static numberTooSmall(label: string, minValue: number): string {
    return this.format('NUMBER_TOO_SMALL', label, minValue);
  }

  /**
   * Format number too large message
   */
  static numberTooLarge(label: string, maxValue: number): string {
    return this.format('NUMBER_TOO_LARGE', label, maxValue);
  }

  /**
   * Format number invalid digits message
   */
  static numberInvalidDigits(label: string, digits: number): string {
    return this.format('NUMBER_INVALID_DIGITS', label, digits);
  }

  /**
   * Format email invalid message
   */
  static emailInvalid(label: string): string {
    return this.format('EMAIL_INVALID', label);
  }

  /**
   * Format phone invalid message
   */
  static phoneInvalid(label: string): string {
    return this.format('PHONE_INVALID', label);
  }

  /**
   * Format phone too short message
   */
  static phoneTooShort(label: string, minDigits: number): string {
    return this.format('PHONE_TOO_SHORT', label, minDigits);
  }

  /**
   * Format phone too long message
   */
  static phoneTooLong(label: string, maxDigits: number): string {
    return this.format('PHONE_TOO_LONG', label, maxDigits);
  }

  /**
   * Format date invalid message
   */
  static dateInvalid(label: string): string {
    return this.format('DATE_INVALID', label);
  }

  /**
   * Format date too early message
   */
  static dateTooEarly(label: string, minDate: string): string {
    return this.format('DATE_TOO_EARLY', label, minDate);
  }

  /**
   * Format date too late message
   */
  static dateTooLate(label: string, maxDate: string): string {
    return this.format('DATE_TOO_LATE', label, maxDate);
  }

  /**
   * Format date past required message
   */
  static datePastRequired(label: string, value: number, unit: string): string {
    return this.format('DATE_PAST_REQUIRED', label, value, unit);
  }

  /**
   * Format date future required message
   */
  static dateFutureRequired(label: string, value: number, unit: string): string {
    return this.format('DATE_FUTURE_REQUIRED', label, value, unit);
  }

  /**
   * Format year invalid format message
   */
  static yearInvalidFormat(label: string): string {
    return this.format('YEAR_INVALID_FORMAT', label);
  }

  /**
   * Format year too early message
   */
  static yearTooEarly(label: string, minYear: number): string {
    return this.format('YEAR_TOO_EARLY', label, minYear);
  }

  /**
   * Format year too late message
   */
  static yearTooLate(label: string, maxYear: number): string {
    return this.format('YEAR_TOO_LATE', label, maxYear);
  }

  /**
   * Format year future not allowed message
   */
  static yearFutureNotAllowed(label: string): string {
    return this.format('YEAR_FUTURE_NOT_ALLOWED', label);
  }

  /**
   * Format year range invalid message
   */
  static yearRangeInvalid(label: string): string {
    return this.format('YEAR_RANGE_INVALID', label);
  }

  /**
   * Format year range start after end message
   */
  static yearRangeStartAfterEnd(label: string): string {
    return this.format('YEAR_RANGE_START_AFTER_END', label);
  }

  /**
   * Format file required message
   */
  static fileRequired(label: string): string {
    return this.format('FILE_REQUIRED', label);
  }

  /**
   * Format file invalid URL message
   */
  static fileInvalidUrl(label: string): string {
    return this.format('FILE_INVALID_URL', label);
  }

  /**
   * Format file invalid type message
   */
  static fileInvalidType(label: string, allowedTypes: string): string {
    return this.format('FILE_INVALID_TYPE', label, allowedTypes);
  }

  /**
   * Format file too small message
   */
  static fileTooSmall(label: string, minSize: number, unit: string): string {
    return this.format('FILE_TOO_SMALL', label, minSize, unit);
  }

  /**
   * Format file too large message
   */
  static fileTooLarge(label: string, maxSize: number, unit: string): string {
    return this.format('FILE_TOO_LARGE', label, maxSize, unit);
  }

  /**
   * Format file video too short message
   */
  static fileVideoTooShort(label: string, minDuration: number, unit: string): string {
    return this.format('FILE_VIDEO_TOO_SHORT', label, minDuration, unit);
  }

  /**
   * Format file video too long message
   */
  static fileVideoTooLong(label: string, maxDuration: number, unit: string): string {
    return this.format('FILE_VIDEO_TOO_LONG', label, maxDuration, unit);
  }

  /**
   * Format selection required message
   */
  static selectionRequired(label: string): string {
    return this.format('SELECTION_REQUIRED', label);
  }

  /**
   * Format selection invalid message
   */
  static selectionInvalid(label: string): string {
    return this.format('SELECTION_INVALID', label);
  }

  /**
   * Format selection too few message
   */
  static selectionTooFew(label: string, minCount: number): string {
    return this.format('SELECTION_TOO_FEW', label, minCount);
  }

  /**
   * Format selection too many message
   */
  static selectionTooMany(label: string, maxCount: number): string {
    return this.format('SELECTION_TOO_MANY', label, maxCount);
  }

  /**
   * Format multiselect invalid array message
   */
  static multiselectInvalidArray(label: string): string {
    return this.format('MULTISELECT_INVALID_ARRAY', label);
  }

  /**
   * Format preference required message
   */
  static preferenceRequired(label: string): string {
    return this.format('PREFERENCE_REQUIRED', label);
  }

  /**
   * Format preference invalid array message
   */
  static preferenceInvalidArray(label: string): string {
    return this.format('PREFERENCE_INVALID_ARRAY', label);
  }

  /**
   * Format multiquestion invalid object message
   */
  static multiquestionInvalidObject(label: string): string {
    return this.format('MULTIQUESTION_INVALID_OBJECT', label);
  }

  /**
   * Format multiquestion subfield required message
   */
  static multiquestionSubfieldRequired(label: string): string {
    return this.format('MULTIQUESTION_SUBFIELD_REQUIRED', label);
  }

  /**
   * Format multiquestion subfield invalid number message
   */
  static multiquestionSubfieldInvalidNumber(label: string): string {
    return this.format('MULTIQUESTION_SUBFIELD_INVALID_NUMBER', label);
  }

  /**
   * Format multiquestion subfield too short message
   */
  static multiquestionSubfieldTooShort(label: string, minLength: number): string {
    return this.format('MULTIQUESTION_SUBFIELD_TOO_SHORT', label, minLength);
  }

  /**
   * Format multiquestion subfield too long message
   */
  static multiquestionSubfieldTooLong(label: string, maxLength: number): string {
    return this.format('MULTIQUESTION_SUBFIELD_TOO_LONG', label, maxLength);
  }

  /**
   * Format address required message
   */
  static addressRequired(label: string): string {
    return this.format('ADDRESS_REQUIRED', label);
  }

  /**
   * Format address too short message
   */
  static addressTooShort(label: string, minLength: number): string {
    return this.format('ADDRESS_TOO_SHORT', label, minLength);
  }

  /**
   * Format address too long message
   */
  static addressTooLong(label: string, maxLength: number): string {
    return this.format('ADDRESS_TOO_LONG', label, maxLength);
  }

  /**
   * Format address invalid format message
   */
  static addressInvalidFormat(label: string): string {
    return this.format('ADDRESS_INVALID_FORMAT', label);
  }

  /**
   * Format dependent pattern invalid message
   */
  static dependentPatternInvalid(label: string): string {
    return this.format('DEPENDENT_PATTERN_INVALID', label);
  }

  /**
   * Format dependent field length mismatch message
   */
  static dependentFieldLengthMismatch(label: string, expectedLength: number): string {
    return this.format('DEPENDENT_FIELD_LENGTH_MISMATCH', label, expectedLength);
  }

  /**
   * Format checkbox required message
   */
  static checkboxRequired(label: string): string {
    return this.format('CHECKBOX_REQUIRED', label);
  }

  /**
   * Format radio required message
   */
  static radioRequired(label: string): string {
    return this.format('RADIO_REQUIRED', label);
  }

  /**
   * Format invalid question ID message
   */
  static invalidQuestionId(questionId: number): string {
    return this.format('INVALID_QUESTION_ID', questionId);
  }

  /**
   * Format registration-specific messages
   */
  static registrationAnswerRequired(label: string): string {
    return this.format('REGISTRATION_ANSWER_REQUIRED', label);
  }

  static registrationAnswerTooShort(label: string, minLength: number): string {
    return this.format('REGISTRATION_ANSWER_TOO_SHORT', label, minLength);
  }

  static registrationAnswerTooLong(label: string, maxLength: number): string {
    return this.format('REGISTRATION_ANSWER_TOO_LONG', label, maxLength);
  }

  static registrationAnswerInvalidPattern(label: string): string {
    return this.format('REGISTRATION_ANSWER_INVALID_PATTERN', label);
  }

  static registrationDependencyNotSatisfied(label: string): string {
    return this.format('REGISTRATION_DEPENDENCY_NOT_SATISFIED', label);
  }
}
