
package de.ivu.elect.exchange.geodata;

import static org.apache.commons.lang3.StringUtils.trimToEmpty;

import org.jsefa.csv.annotation.CsvDataType;
import org.jsefa.csv.annotation.CsvField;

import de.ivu.elect.exchange.BaseDTO;
import de.ivu.jsefa.CsvHeader;

@CsvDataType
public class DestatisGeodataOrtCsvDTO extends BaseDTO {

  private static final String GEMEINDENAMEZUSATZ_COMMON_SUFFIX_PATTERN = "\\b.*gebiet|\\b.*bezirk|\\b.*stadt?|\\b.*gemeinde|\\b.*ort|\\b.*bad|\\b.*flecken|\\b.*kirchspiel|\\b.*(krst|gkst|st|m)\\.?";

  private static final String GEMEINDENAMEZUSATZ_CUSTOM_SUFFIX_PATTERN = "NRW\\-Klimakommune|Tor zur Eifel";

  private static final String GEMEINDENAME_PATTERN = "(?i)^(.*)\\s*,\\s*(" + GEMEINDENAMEZUSATZ_COMMON_SUFFIX_PATTERN + "|"
      + GEMEINDENAMEZUSATZ_CUSTOM_SUFFIX_PATTERN + ")?$";

  @CsvField(pos = 3)
  @CsvHeader("Land")
  private String bundeslandname;

  @CsvField(pos = 2)
  @CsvHeader("Gemeindename_amtlich")
  private String gemeindename;

  @CsvField(pos = 1)
  @CsvHeader("PLZ")
  private String plz;

  public DestatisGeodataOrtCsvDTO() {
    super();
  }

  public String getBundeslandname() {
    return bundeslandname;
  }

  public void setBundeslandname(String bundeslandname) {
    this.bundeslandname = trimToEmpty(bundeslandname);
  }

  public String getGemeindename() {
    return gemeindename;
  }

  public void setGemeindename(String gemeindename) {
    this.gemeindename = trimToEmpty(gemeindename);
  }

  public String getPlz() {
    return plz;
  }

  public void setPlz(String plz) {
    this.plz = trimToEmpty(plz);
  }

  public String getOrtsname() {
    return trimToEmpty(gemeindename).replaceAll(GEMEINDENAME_PATTERN, "$1").trim();
  }
}
