from orangescape.model.server.SystemInterface import Dynamic,Static,Data

def dictCopy(dt):
    copyDt = dict()
    for key, value in dt.iteritems():
        copyDt[key] = value
    return copyDt

class AbstractData(Data, object):
    _dynamic_properties = None
    def __init__(self, SheetId, data = None):
        if data is None:
            self._dynamic_properties = dict()
            self.SheetId = SheetId
        else:
            self._dynamic_properties = data

    def setSheetId(self, SheetId):
        self._dynamic_properties['SheetId'] = SheetId

    def getSheetId(self):
        return self._dynamic_properties['SheetId']

    def setMetadataId(self, metadataId):
        self._dynamic_properties['SheetMetadataId'] = metadataId

    def getMetadataId(self):
        return self._dynamic_properties['SheetMetadataId']

    def getSheetMetadataId(self):
        return self.getMetadataId()

    def setModifiedAt(self, modifiedAt):
        self._dynamic_properties['ModifiedAt'] = modifiedAt

    def getModifiedAt(self):
        return self._dynamic_properties['ModifiedAt']

    def setApplicationId(self, applicationId):
        self._dynamic_properties['ApplicationId'] = applicationId

    def getApplicationId(self):
        return self._dynamic_properties['ApplicationId']

    def get(self,cellMetadata):
        return self._dynamic_properties.get(cellMetadata.getSheetId())

    def set(self,cellMetadata,value):
        if value is not None:
            self._dynamic_properties[cellMetadata.getSheetId()] = value
        elif self._dynamic_properties.__contains__(cellMetadata.getSheetId()):
            del self._dynamic_properties[cellMetadata.getSheetId()]

    def getCopy(self):
        return self

    def getPrivateData(self):
        return dictCopy(self._dynamic_properties)

    def getDynamicProperties(self):
        return self._dynamic_properties

    SheetMetadataId = property(getMetadataId, setMetadataId)
    SheetId = property(getSheetId, setSheetId)
    ApplicationId = property(getApplicationId, setApplicationId)
    ModifiedAt = property(getModifiedAt, setModifiedAt)

class PrimaryData(AbstractData):
    def getClass(self):
        return PrimaryData

class SecondaryData(AbstractData):
    def getClass(self):
        return SecondaryData
