from .StoredProcedureOperation import StoredProcedureOperation
from ..core.Guid import Guid
from ..SQLParameter import SQLParameter
from ..SQLFunctionCall import SQLFunctionCall

class AssignAttributeOperation(StoredProcedureOperation):

	def __init__(self, instanceId : Guid, attributeInstanceId : Guid, value):
		self.instanceId = instanceId
		self.attributeInstanceId = attributeInstanceId
		self.value = value

	def get_sp_name(self):
		return "mocha_set_attribute_value"

	def get_sp_parameters(self):
		return [ SQLFunctionCall('mocha_get_instance_by_global_identifier', [ self.instanceId ]), SQLFunctionCall('mocha_get_instance_by_global_identifier', [ self.attributeInstanceId ]), str(self.value), None, None ]
		#query = "CALL mocha_set_attribute_value(mocha_get_instance_by_global_identifier(mocha_normalize_uuid('" + instanceId.get_value() + "')), mocha_get_instance_by_global_identifier(mocha_normalize_uuid('" + attributeInstanceId.get_value() + "')), '" + str(value) + "', NULL, NULL);"
		#print(query)
		#cur.execute(query)
		#self.print_error(cur)