package ru.micord.ervu.account_applications.component.property.grid.formatter;

import property.grid.Formatter;

/**
 * @author Adel Kalimullin
 */
public class ErvuSnilsFormatter implements Formatter<String, String> {
  @Override
  public String format(String value) {
    if (value == null) {
      return null;
    }

    String number = value.replaceAll("\\D", "");

    if (number.length() != 11) {
      throw new IllegalArgumentException("Некорректный формат СНИЛС: " + number);
    }

    return number.substring(0, 3) + "-" +
           number.substring(3, 6) + "-" +
           number.substring(6, 9) + " " +
           number.substring(9);
  }
}
