# 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 CIM14.IEC61970.Core.PowerSystemResource import PowerSystemResource

class PrimeMover(PowerSystemResource):
    """The machine used to develop mechanical energy used to drive a generator.
    """

    def __init__(self, primeMoverRating=0.0, SynchronousMachines=None, *args, **kw_args):
        """Initialises a new 'PrimeMover' instance.

        @param primeMoverRating: Rating of prime mover 
        @param SynchronousMachines: Synchronous machines this Prime mover drives.
        """
        #: Rating of prime mover
        self.primeMoverRating = primeMoverRating

        self._SynchronousMachines = []
        self.SynchronousMachines = [] if SynchronousMachines is None else SynchronousMachines

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

    _attrs = ["primeMoverRating"]
    _attr_types = {"primeMoverRating": float}
    _defaults = {"primeMoverRating": 0.0}
    _enums = {}
    _refs = ["SynchronousMachines"]
    _many_refs = ["SynchronousMachines"]

    def getSynchronousMachines(self):
        """Synchronous machines this Prime mover drives.
        """
        return self._SynchronousMachines

    def setSynchronousMachines(self, value):
        for p in self._SynchronousMachines:
            filtered = [q for q in p.PrimeMovers if q != self]
            self._SynchronousMachines._PrimeMovers = filtered
        for r in value:
            if self not in r._PrimeMovers:
                r._PrimeMovers.append(self)
        self._SynchronousMachines = value

    SynchronousMachines = property(getSynchronousMachines, setSynchronousMachines)

    def addSynchronousMachines(self, *SynchronousMachines):
        for obj in SynchronousMachines:
            if self not in obj._PrimeMovers:
                obj._PrimeMovers.append(self)
            self._SynchronousMachines.append(obj)

    def removeSynchronousMachines(self, *SynchronousMachines):
        for obj in SynchronousMachines:
            if self in obj._PrimeMovers:
                obj._PrimeMovers.remove(self)
            self._SynchronousMachines.remove(obj)

