#PLEASE DO NOT EDIT THIS CODE
#This code was generated using the UMPLE 1.32.1.6535.66c005ced modeling language!
# line 3 "../OneToMNTest.ump"

class Mentor():
    #------------------------
    # MEMBER VARIABLES
    #------------------------
    #Mentor Attributes
    #Mentor Associations
    #------------------------
    # CONSTRUCTOR
    #------------------------
    def __init__(self, aName):
        self._pupils = None
        self._name = None
        self._name = aName
        self._pupils = []

    #------------------------
    # INTERFACE
    #------------------------
    def setName(self, aName):
        wasSet = False
        self._name = aName
        wasSet = True
        return wasSet

    def getName(self):
        return self._name

    # Code from template association_GetMany 
    def getPupil(self, index):
        aPupil = self._pupils[index]
        return aPupil

    def getPupils(self):
        newPupils = tuple(self._pupils)
        return newPupils

    def numberOfPupils(self):
        number = len(self._pupils)
        return number

    def hasPupils(self):
        has = len(self._pupils) > 0
        return has

    def indexOfPupil(self, aPupil):
        index = (-1 if not aPupil in self._pupils else self._pupils.index(aPupil))
        return index

    # Code from template association_IsNumberOfValidMethod 
    def isNumberOfPupilsValid(self):
        isValid = self.numberOfPupils() >= Mentor.minimumNumberOfPupils() and self.numberOfPupils() <= Mentor.maximumNumberOfPupils()
        return isValid

    # Code from template association_MinimumNumberOfMethod 
    @staticmethod
    def minimumNumberOfPupils():
        return 5

    # Code from template association_MaximumNumberOfMethod 
    @staticmethod
    def maximumNumberOfPupils():
        return 7

    # Code from template association_AddMNToOnlyOne 
    def addPupil1(self, aNumber):
        from Pupil import Pupil
        if self.numberOfPupils() >= Mentor.maximumNumberOfPupils() :
            return None
        else :
            return Pupil(aNumber, self)

    def addPupil2(self, aPupil):
        wasAdded = False
        if (aPupil) in self._pupils :
            return False
        if self.numberOfPupils() >= Mentor.maximumNumberOfPupils() :
            return wasAdded
        existingMentor = aPupil.getMentor()
        isNewMentor = not (existingMentor is None) and not self == existingMentor
        if isNewMentor and existingMentor.numberOfPupils() <= Mentor.minimumNumberOfPupils() :
            return wasAdded
        if isNewMentor :
            aPupil.setMentor(self)
        else :
            self._pupils.append(aPupil)
        wasAdded = True
        return wasAdded

    def removePupil(self, aPupil):
        wasRemoved = False
        #Unable to remove aPupil, as it must always have a mentor
        if self == aPupil.getMentor() :
            return wasRemoved
        #mentor already at minimum (5)
        if self.numberOfPupils() <= Mentor.minimumNumberOfPupils() :
            return wasRemoved
        self._pupils.remove(aPupil)
        wasRemoved = True
        return wasRemoved

    # Code from template association_AddIndexControlFunctions 
    def addPupilAt(self, aPupil, index):
        wasAdded = False
        if self.addPupil(aPupil) :
            if index < 0 :
                index = 0
            if index > self.numberOfPupils() :
                index = self.numberOfPupils() - 1
            self._pupils.remove(aPupil)
            self._pupils.insert(index, aPupil)
            wasAdded = True
        return wasAdded

    def addOrMovePupilAt(self, aPupil, index):
        wasAdded = False
        if (aPupil) in self._pupils :
            if index < 0 :
                index = 0
            if index > self.numberOfPupils() :
                index = self.numberOfPupils() - 1
            self._pupils.remove(aPupil)
            self._pupils.insert(index, aPupil)
            wasAdded = True
        else :
            wasAdded = self.addPupilAt(aPupil, index)
        return wasAdded

    def delete(self):
        i = len(self._pupils)
        while i > 0 :
            aPupil = self._pupils[i - 1]
            aPupil.delete()
            i -= 1

    def __str__(self):
        return str(super().__str__()) + "[" + "name" + ":" + str(self.getName()) + "]"

    def addPupil(self, *argv):
        from Pupil import Pupil
        if len(argv) == 1 and isinstance(argv[0], str) :
            return self.addPupil1(argv[0])
        if len(argv) == 1 and isinstance(argv[0], Pupil) :
            return self.addPupil2(argv[0])
        raise TypeError("No method matches provided parameters")

