
package de.ivu.elect.exchange.staat.mapper;

import static java.util.Collections.emptyList;

import java.util.Collection;
import java.util.stream.Collectors;

import de.ivu.elect.business.staat.entity.Staat;
import de.ivu.elect.jee.entity.customdata.DefaultCustomData;

public class StaatMapper {

  public StaatMapper() {
    super();
  }

  public Collection<Staat> intern(Collection<de.ivu.elect.interfaces.core.Staat> sources) {
    if (sources == null || sources.isEmpty()) {
      return emptyList();
    }

    return sources.stream().map(this::intern).collect(Collectors.toList());
  }

  public Staat intern(de.ivu.elect.interfaces.core.Staat source) {
    Staat target = new Staat(new DefaultCustomData());
    intern(source, target);

    return target;
  }

  public void intern(de.ivu.elect.interfaces.core.Staat source, Staat target) {
    target.setIso3166Alpha2(source.getIso3166Alpha2());
    target.setCustomCodeStaat(source.getCustomCodeStaat());
    target.setCustomCodeStaatsangehoerigkeit(source.getCustomCodeStaatsangehoerigkeit());
  }

  public Collection<de.ivu.elect.interfaces.core.Staat> extern(Collection<Staat> sources) {
    if (sources == null || sources.isEmpty()) {
      return emptyList();
    }

    return sources.stream().map(this::extern).collect(Collectors.toList());
  }

  public de.ivu.elect.interfaces.core.Staat extern(Staat source) {
    de.ivu.elect.interfaces.core.Staat target = new de.ivu.elect.interfaces.core.Staat();
    extern(source, target);

    return target;
  }

  public void extern(Staat source, de.ivu.elect.interfaces.core.Staat target) {
    target.setIso3166Alpha2(source.getIso3166Alpha2());
    target.setCustomCodeStaat(source.getCustomCodeStaat());
    target.setCustomCodeStaatsangehoerigkeit(source.getCustomCodeStaatsangehoerigkeit());
  }
}
