import sys
sys.path.append("wrappers")
from modelverse import *

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

mm = \
"""
include "primitives.alh"

SimpleAttribute integer {
    constraint = $
        String function constraint(value : Element):
            if is_physical_int(value):
                return "OK"!
            else:
                return "Expected integer value instead of '" + cast_string(value) + "'"!
        $
}
SimpleAttribute string {
    constraint = $
        String function constraint(value : Element):
            if is_physical_string(value):
                return "OK"!
            else:
                return "Expected string value instead of '" + cast_string(value) + "'"!
        $
}

Class A {
    d : integer
    name = "A"
}
Class B {
    d : string
    name = "B"
}
Class C {
    name = "C"
}

Inheritance (C, A) {}
Inheritance (C, B) {}
"""

model_string = \
"""
C {
    d = "a"
}
"""

model_integer = \
"""
C {
    d = 1
}
"""

model_add("formalisms/simple_mm", "formalisms/SimpleClassDiagrams", mm)
model_add("models/model_string", "formalisms/simple_mm", model_string)
model_add("models/model_integer", "formalisms/simple_mm", model_integer)

transformation_add_AL({"model": "formalisms/Bottom", "metamodel": "formalisms/SimpleClassDiagrams", "type_mapping": "formalisms/TypeMapping"}, {}, "models/conformance_AToMPM", open("models/Conformance/AToMPM.alc", 'r').read())
transformation_add_AL({"model": "formalisms/Bottom", "metamodel": "formalisms/SimpleClassDiagrams", "type_mapping": "formalisms/TypeMapping"}, {}, "models/conformance_MetaDepth", open("models/Conformance/MetaDepth.alc", 'r').read())

print("Checking conformance of model with Integer in AToMPM semantics:")
print(transformation_execute_AL("models/conformance_AToMPM", {"model": "models/model_integer", "metamodel": "formalisms/simple_mm", "type_mapping": model_types("models/model_integer").pop()[1]}, {}))
print("Checking conformance of model with String in AToMPM semantics:")
print(transformation_execute_AL("models/conformance_AToMPM", {"model": "models/model_string", "metamodel": "formalisms/simple_mm", "type_mapping": model_types("models/model_string").pop()[1]}, {}))
print("Checking conformance of model with Integer in MetaDepth semantics:")
print(transformation_execute_AL("models/conformance_MetaDepth", {"model": "models/model_integer", "metamodel": "formalisms/simple_mm", "type_mapping": model_types("models/model_integer").pop()[1]}, {}))
print("Checking conformance of model with String in MetaDepth semantics:")
print(transformation_execute_AL("models/conformance_MetaDepth", {"model": "models/model_string", "metamodel": "formalisms/simple_mm", "type_mapping": model_types("models/model_string").pop()[1]}, {}))
