def updateShifts(shifts, oldBar, oldBartender, oldDate):
    bartenderRepo = BartenderRepo.BartenderRepo()
    bartenderArray = bartenderRepo.getBartender(shifts.getBartender())
    if variable.isEmptyArray(bartenderArray):
        raise Error("Bartender does not exist")

    #pattern 5
    shiftsRepo = ShiftsRepo.ShiftsRepo()
    items = shiftsRepo.getShifts(shifts.getBartender(), shifts.getDate())
    if len(items) != 0 and (not (shifts.getBartender() == oldBartender)
                            or not (shifts.getBar() == oldBar)
                            or not (shifts.getDate() == oldDate)):
        raise Error("Bartender can only have one shift on a given date")

    barRepo = BarRepo.BarRepo()
    barArray = barRepo.getBar(shifts.getBar())
    if variable.isEmptyArray(barArray):
        raise Error("Bar does not exist")

    datetime_object = datetime.strptime(shifts.getDate(), "%Y-%m-%d")
    if str(calendar.day_name[datetime_object.weekday()]) != str(
            shifts.getDay()):
        raise Error("Day does not match date")

    if shifts.getStart() >= shifts.getEnd():
        raise Error("shifts hour error: start time cannot be before end time")

    operatesRepo = OperatesRepo.OperatesRepo()
    if not operatesRepo.shift_during_operating_hours(
            shifts.getStart(), shifts.getEnd(), shifts.getBar(),
            shifts.getDate()):
        raise Error("bar does not operate during that shift")

    if barArray[0].getState() != bartenderArray[0].getState():
        raise Error("bartender cannot live in a different state than the bar")

    billsRepo = BillsRepo.BillsRepo()
    transcations = billsRepo.getBillsByBartenderAndDate(
        shifts.getBartender(), shifts.getDate())

    for each in transcations:
        if not (shifts.getStart() <= each.getTime()
                and each.getTime() <= shifts.getEnd()):
            raise Error(
                "Bartender has transcations during the current shift that need to be deleted or updated before trying to update this shift"
            )

    shiftsRepo = ShiftsRepo.ShiftsRepo()
    return shiftsRepo.updateShifts(shifts, oldBar, oldBartender, oldDate)
def deleteShifts(shifts):
    billsRepo = BillsRepo.BillsRepo()
    transcations = billsRepo.getBillsByBartenderAndDate(
        shifts.getBartender(), shifts.getDate())
    if not variable.isEmptyArray(transcations):
        raise Error(
            "Bartender has transcations during the shift, please delete them before trying to delete shift"
        )
    shiftsRepo = ShiftsRepo.ShiftsRepo()
    return shiftsRepo.deleteShifts(shifts)
def insertShifts(shifts):

    bartenderRepo = BartenderRepo.BartenderRepo()
    bartenderArray = bartenderRepo.getBartender(shifts.getBartender())
    if variable.isEmptyArray(bartenderArray):
        raise Error("Bartender does not exist")

    shiftsRepo = ShiftsRepo.ShiftsRepo()
    items = shiftsRepo.getShifts(shifts.getBartender(), shifts.getDate())
    if len(items) != 0:
        raise Error("Bartender can only have one shift on a given date")

    barRepo = BarRepo.BarRepo()
    barArray = barRepo.getBar(shifts.getBar())
    if variable.isEmptyArray(barArray):
        raise Error("Bar does not exist")

    datetime_object = datetime.strptime(shifts.getDate(), "%Y-%m-%d")
    if str(calendar.day_name[datetime_object.weekday()]) != str(
            shifts.getDay()):
        raise Error("Day does not match date")

    if shifts.getStart() >= shifts.getEnd():
        raise Error("shifts hour error: start time cannot be before end time")

    operatesRepo = OperatesRepo.OperatesRepo()
    if not operatesRepo.shift_during_operating_hours(
            shifts.getStart(), shifts.getEnd(), shifts.getBar(),
            shifts.getDate()):
        raise Error("bar does not operate during that shift")

    if barArray[0].getState() != bartenderArray[0].getState():
        raise Error("bartender cannot live in a different state than the bar")

    shiftsRepo = ShiftsRepo.ShiftsRepo()
    return shiftsRepo.insertShifts(shifts)