from .McxInstance import McxInstance
from .McxAttribute import McxAttribute
from .McxRelationship import McxRelationship

from editor.core import ObjectModel

class McxObjectModel (ObjectModel):

	def __init__(self):
		super().__init__()
		self._instances = list[McxInstance]()
		self._attributes = list[McxAttribute]()
		self._relationships = list[McxRelationship]()

		self.__entityDefinitionsKeys = dict()
		self.__entityDefinitionsValues = dict()

		self.template_definitions = dict()
		self.__guid = None

	def get_guid(self):
		return self.__guid
	def set_guid(self, guid):
		self.__guid = guid

	def get_instances(self) -> list[McxInstance]:
		return self._instances
	
	def get_attributes(self) -> list[McxAttribute]:
		return self._attributes
	
	def get_relationships(self) -> list[McxRelationship]:
		return self._relationships
	
	def define_entity(self, key : str, value : str):
		self.__entityDefinitionsKeys[value] = key
		self.__entityDefinitionsValues[key] = value

	def get_entity_definitions(self):
		defs = [ ]
		for key in self.get_entity_keys():
			value = self.get_entity_value(key)
			defs.append((key, value))
		return defs
	
	def get_entity_key(self, value : str):
		return self.__entityDefinitionsKeys[value]
	def get_entity_keys(self):
		return self.__entityDefinitionsValues.keys()
	
	def get_entity_value(self, key : str):
		return self.__entityDefinitionsValues[key]
	def get_entity_values(self):
		return self.__entityDefinitionsKeys.keys()
	
	def has_entity_key(self, key : str):
		return key in self.__entityDefinitionsValues
	def has_entity_value(self, value : str):
		return value in self.__entityDefinitionsKeys

	def get_template_definitions(self):
		return self.template_definitions
	def register_template_definition(self, key , value):
		self.template_definitions[key] = value