# Copyright (C) 2010-2011 Richard Lincoln
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

from CIM15.IEC61968.Assets.Asset import Asset

class TransformerAsset(Asset):
    """A specific physical (vs. logical) transformer.A specific physical (vs. logical) transformer.
    """

    def __init__(self, reconditionedDateTime='', PowerRatings=None, TransformerObservations=None, TransformerInfo=None, TransformerAssetModel=None, *args, **kw_args):
        """Initialises a new 'TransformerAsset' instance.

        @param reconditionedDateTime: Date and time this asset was last reconditioned or had a major overhaul. 
        @param PowerRatings:
        @param TransformerObservations:
        @param TransformerInfo:
        @param TransformerAssetModel:
        """
        #: Date and time this asset was last reconditioned or had a major overhaul.
        self.reconditionedDateTime = reconditionedDateTime

        self._PowerRatings = []
        self.PowerRatings = [] if PowerRatings is None else PowerRatings

        self._TransformerObservations = []
        self.TransformerObservations = [] if TransformerObservations is None else TransformerObservations

        self._TransformerInfo = None
        self.TransformerInfo = TransformerInfo

        self._TransformerAssetModel = None
        self.TransformerAssetModel = TransformerAssetModel

        super(TransformerAsset, self).__init__(*args, **kw_args)

    _attrs = ["reconditionedDateTime"]
    _attr_types = {"reconditionedDateTime": str}
    _defaults = {"reconditionedDateTime": ''}
    _enums = {}
    _refs = ["PowerRatings", "TransformerObservations", "TransformerInfo", "TransformerAssetModel"]
    _many_refs = ["PowerRatings", "TransformerObservations"]

    def getPowerRatings(self):
        
        return self._PowerRatings

    def setPowerRatings(self, value):
        for p in self._PowerRatings:
            filtered = [q for q in p.TransformerAssets if q != self]
            self._PowerRatings._TransformerAssets = filtered
        for r in value:
            if self not in r._TransformerAssets:
                r._TransformerAssets.append(self)
        self._PowerRatings = value

    PowerRatings = property(getPowerRatings, setPowerRatings)

    def addPowerRatings(self, *PowerRatings):
        for obj in PowerRatings:
            if self not in obj._TransformerAssets:
                obj._TransformerAssets.append(self)
            self._PowerRatings.append(obj)

    def removePowerRatings(self, *PowerRatings):
        for obj in PowerRatings:
            if self in obj._TransformerAssets:
                obj._TransformerAssets.remove(self)
            self._PowerRatings.remove(obj)

    def getTransformerObservations(self):
        
        return self._TransformerObservations

    def setTransformerObservations(self, value):
        for x in self._TransformerObservations:
            x.TransformerAsset = None
        for y in value:
            y._TransformerAsset = self
        self._TransformerObservations = value

    TransformerObservations = property(getTransformerObservations, setTransformerObservations)

    def addTransformerObservations(self, *TransformerObservations):
        for obj in TransformerObservations:
            obj.TransformerAsset = self

    def removeTransformerObservations(self, *TransformerObservations):
        for obj in TransformerObservations:
            obj.TransformerAsset = None

    def getTransformerInfo(self):
        
        return self._TransformerInfo

    def setTransformerInfo(self, value):
        if self._TransformerInfo is not None:
            filtered = [x for x in self.TransformerInfo.TransformerAssets if x != self]
            self._TransformerInfo._TransformerAssets = filtered

        self._TransformerInfo = value
        if self._TransformerInfo is not None:
            if self not in self._TransformerInfo._TransformerAssets:
                self._TransformerInfo._TransformerAssets.append(self)

    TransformerInfo = property(getTransformerInfo, setTransformerInfo)

    def getTransformerAssetModel(self):
        
        return self._TransformerAssetModel

    def setTransformerAssetModel(self, value):
        if self._TransformerAssetModel is not None:
            filtered = [x for x in self.TransformerAssetModel.TransformerAssets if x != self]
            self._TransformerAssetModel._TransformerAssets = filtered

        self._TransformerAssetModel = value
        if self._TransformerAssetModel is not None:
            if self not in self._TransformerAssetModel._TransformerAssets:
                self._TransformerAssetModel._TransformerAssets.append(self)

    TransformerAssetModel = property(getTransformerAssetModel, setTransformerAssetModel)

