from events.PointEvent import PointEvent
from events.EndOfBallEvent import EndOfBallEvent
from events.RightFlapEvent import RightFlapEvent
from events.LeftFlapEvent import LeftFlapEvent
from events.RightKickerEvent import RightKickerEvent
from events.EnterUpperPlayfieldEvent import EnterUpperPlayfieldEvent
from events.StartGameEvent import StartGameEvent

class EventFactory:
    def __init__(self, targets, currentPlayer, upperPlayfieldFlippers, flipper):
        self.targets = targets
        self.currentPlayer = currentPlayer
        self.upperPlayfieldFlippers = upperPlayfieldFlippers
        self.flipper = flipper
        
    def createPointEvent(self):
        event = PointEvent(self.currentPlayer)
        for target in self.targets:
            self.__registerEventToTarget(event, target)
        return event

    def createEndOfBallEvent(self):
        event = EndOfBallEvent(self.currentPlayer)
        self.__registerEventToTarget(event, self.targets['OutholeTarget'])
        return event

    def createRightFlapEvent(self):
        event = RightFlapEvent()
        self.__registerEventToTarget(event, self.targets['RightSlingshotTarget'])
        return event

    def createLeftFlapEvent(self):
        event = LeftFlapEvent()
        self.__registerEventToTarget(event, self.targets['LeftSlingshotTarget'])
        return event

    def createRightKickerEvent(self):
        event = RightKickerEvent()
        self.__registerEventToTarget(event, self.targets['RightOutlaneKickerTarget'])
        return event

    def createEnterUpperPlayfieldEvent(self):
        event = EnterUpperPlayfieldEvent(self.currentPlayer, self.upperPlayfieldFlippers)
        self.__registerEventToTarget(event, self.targets['UpperPlayfieldRollUnderTarget'])
        return event

    def createStartGameEvent(self):
        event = StartGameEvent(self.flipper)
        self.__registerEventToTarget(event, self.targets['CreditTarget'])
        return event

    def __registerEventToTarget(self, event, target):
        target.on(target.hit_key, event.trigger)
