from Car import Car

import copy

class Flow:
    def __init__(self,ID,route,start,vph,parentMap,parentController):
        self.route = route
        self.id = ID
        self.startTime = start
        self.vph = float(vph)
        self.carModel = Car("model",self.route,start,parentMap,parentController,None)
        self.carsSpawned = 0

    def prepareRoute(self):
        self.carModel.prepareRoute()
    
    def shouldSpawn(self, t):
        f = self.carsSpawned / (t/3600)
        return f < self.vph

    def spawnCar(self):
        newCar = copy.copy(self.carModel)
        newCar.id = self.id + str(self.carsSpawned)
        self.carsSpawned += 1
        return newCar
