package org.texttechnologylab.project.gruppe_05_1.xml.mdb;

import org.texttechnologylab.project.gruppe_05_1.domain.mdb.MdbName;
import org.texttechnologylab.project.gruppe_05_1.util.GeneralUtils;
import org.texttechnologylab.project.gruppe_05_1.util.Logger;
import org.texttechnologylab.project.gruppe_05_1.xml.XmlOperations;
import org.w3c.dom.Node;

public class MdbName_File_Impl extends MdbName implements XmlOperations {
    @Override
    public MdbName fromXmlNode(Node node) {
        Node current = node.getFirstChild();
        Node child;
        MdbName name = new MdbName_File_Impl();

        while (null != current) {
            child = current.getFirstChild();
            switch (current.getNodeName()) {
                case "NACHNAME":
                    name.setNachname(null == child ? null : child.getNodeValue());
                    break;

                case "VORNAME":
                    name.setVorname(null == child ? null : child.getNodeValue());
                    break;

                case "ORTSZUSATZ":
                    name.setOrtszusatz(null == child ? null : child.getNodeValue());
                    break;

                case "ADEL":
                    name.setAdel(null == child ? null : child.getNodeValue());
                    break;

                case "PRAEFIX":
                    name.setPraefix(null == child ? null : child.getNodeValue());
                    break;

                case "ANREDE_TITEL":
                    name.setAndereTitel(null == child ? null : child.getNodeValue());
                    break;

                case "AKAD_TITEL":
                    name.setAkadTitel(null == child ? null : child.getNodeValue());
                    break;

                case "HISTORIE_VON":
                    name.setHistorieVon(null == child ? null : GeneralUtils.parseDate(child.getNodeValue()));
                    break;

                case "HISTORIE_BIS":
                    name.setHistorieBis(null == child ? null : GeneralUtils.parseDate(child.getNodeValue()));
                    break;

                case "#text":
                    break;

                default:
                    Logger.error("Node name does not match anything known in Name: " + current.getNodeName());
            }

            current = current.getNextSibling();
        }

        return name;
    }
}
