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

import org.texttechnologylab.project.gruppe_05_1.domain.mdb.Mdb;
import org.texttechnologylab.project.gruppe_05_1.domain.mdb.MdbDocument;
import org.texttechnologylab.project.gruppe_05_1.util.XmlUtils;
import org.texttechnologylab.project.gruppe_05_1.xml.XmlOperations;
import org.w3c.dom.Node;

import java.util.ArrayList;
import java.util.List;

public class MdbDocument_File_Impl extends MdbDocument implements XmlOperations {
    @Override
    public MdbDocument fromXmlNode(Node node) {
        MdbDocument doc = new MdbDocument_File_Impl();

        Node versionNode = XmlUtils.getFirstChildByName(node, "VERSION");
        assert versionNode != null;
        doc.setVersion(versionNode.getFirstChild().getNodeValue());

        List<Mdb> mdbs = new ArrayList<>();
        List<Node> mdbNodeList = XmlUtils.getChildrenByName(node, "MDB");
        for (Node mdbNode : mdbNodeList) {
            Mdb mdb = factory.createMdb(mdbNode);
            mdbs.add(mdb);
        }
        doc.setMdbs(mdbs);

        return doc;
    }
}
