from modelverse import *

init()
login("admin", "admin")

model_add("MetamodelA", "SimpleClassDiagrams", """Class A {}""")
model_add("MetamodelB", "SimpleClassDiagrams", """Class B {}""")
model_add("MetamodelC", "SimpleClassDiagrams", """Class C {}""")
model_add("ModelA", "MetamodelA", """A a1 {}""")
model_add("ModelB", "MetamodelB", """B b1 {}""")

model_add("SCCD", "SimpleClassDiagrams", open("models/SCCD.mvc", 'r').read())
model_add("my_SCCD", "SCCD", open("models/test_operations_in_SCCD.mvc", 'r').read())

transformation_add_MT({"A": "MetamodelA", "B": "MetamodelB"}, {"B": "MetamodelB", "C": "MetamodelC"}, "TransformY", \
    """
    Composite schedule {
        {Contains} Failure fail {}
        {Contains} Success success {}
        {Contains} ForAll f {
            LHS {
                Pre_A/A {
                    label = "0"
                }
            }
            RHS {
                Post_C/C {
                    label = "1"
                }
            }
        }
    }
    Initial (schedule, f) {}
    OnSuccess (f, success) {}
    OnFailure (f, fail) {}
    """
    )

transformation_add_AL({"B": "MetamodelB", "C": "MetamodelC"}, {"B": "MetamodelB", "A": "MetamodelA"}, "OperationZ", \
    """
    include "primitives.alh"
    include "object_operations.alh"
    include "modelling.alh"

    Boolean function size_of_model(model : Element):
        log("Number of instances of A: " + cast_value(set_len(allInstances(model, "A/A"))))
        log("Number of instances of B: " + cast_value(set_len(allInstances(model, "B/B"))))
        log("Number of instances of C: " + cast_value(set_len(allInstances(model, "C/C"))))
        return True!
    """
    )
transformation_add_AL({"SCCD": "SCCD"}, {}, "SCCD_execute", open("models/SCCD_execute.alc", 'r').read())

transformation_execute_AL("SCCD_execute", {"SCCD": "my_SCCD"}, {})
