package de.ivu.elect.nl.interfaces.gbav.mapper;

import de.ivu.elect.nl.interfaces.gbav.GbavConstants;

import java.util.Map;
import java.util.Set;


public class GbavLandMapper extends AbstractGbavCodeToNameMapper {

  // Steps to update this file:
  // 1. Open corresponding PDF file in Adobe Acrobat Reader.
  // 2. Save as text file.
  // 3. Remove all lines which contain no code from the text file.
  private static final String FILENAME = "Table34_Landen.txt";

  private final static String DEFAULT_COUNTRY = "NL";

  private final Map<String, String> countryNameToIsoCodeMap;

  public GbavLandMapper() {
    super();
    countryNameToIsoCodeMap = CountryUtil.getNameToIsoCodeMap();
  }

  @Override
  String getFilename() {
    return FILENAME;
  }

  /**
   * @return ISO code of the given country. If no ISO code can be matched, it returns the name of
   *         the country.
   */
  public String mapGbavCodeToIsoCode(String gbavCode) {
    if (gbavCode == null || gbavCode.equals(GbavConstants.DEFAULT_COUNTRY_CODE)) {
      return DEFAULT_COUNTRY;
    }

    String countryName = mapCodeToName(gbavCode);
    String isoCode = countryNameToIsoCodeMap.get(countryName);
    if (isoCode == null) {
      return countryName;
    }
    return isoCode;
  }

  Set<String> getAllCountryCodes() {
    return codeToNameMap.keySet();

  }
}
