package org.mps_cli.model.builder

import org.mps_cli.model.SModel
import org.mps_cli.model.SModelRef

class AbstractModelBuilder {

    BuildingDepthEnum buildingStrategy;

    SModel buildModelFromXML(Node modelXMLNode) {
        def sModel = new SModel()
        def ref = modelXMLNode.'@ref'
        sModel.modelId = ref.substring(0, ref.indexOf('('))
        sModel.name = ref.substring(ref.indexOf('(') + 1, ref.indexOf(')'))

        sModel.isDoNotGenerate = modelXMLNode.attribute.any{ it.'@name'.equals("doNotGenerate") && it.'@value'.equals("true")  }

        for (Node imp : modelXMLNode.imports.import) {
            def modelRefString = imp.'@ref'
            def modelIdRefString = modelRefString.substring(0, ref.indexOf('('))
            sModel.imports.add(new SModelRef(referencedModelId : modelIdRefString))
        }

        sModel
    }
}
