package models;

import exceptions.NoAvailableParkingSpace;
import exceptions.NoSuchCarInParkingLot;

import java.util.List;
import java.util.UUID;

public class ParkingBoy {
    private final List<ParkingLot> parkingLots;

    public ParkingBoy(List<ParkingLot> parkingLots) {
        this.parkingLots = parkingLots;
    }

    public UUID park(Car car) throws NoAvailableParkingSpace {
        UUID ticket = null;
        for (ParkingLot parkingLot : parkingLots) {
            try {
                ticket = parkingLot.park(car);
                break;
            } catch (NoAvailableParkingSpace noAvailableParkingSpace) {
                noAvailableParkingSpace.printStackTrace();
            }
        }
        if (ticket == null) {
            throw new NoAvailableParkingSpace();
        }
        return ticket;
    }

    public Car pick(UUID ticket) throws NoSuchCarInParkingLot {
        Car car = null;
        for (ParkingLot parkingLot : parkingLots) {
            try {
                car = parkingLot.pick(ticket);
                break;
            } catch (NoSuchCarInParkingLot noSuchCarInParkingLot) {
                noSuchCarInParkingLot.printStackTrace();
            }
        }
        if (car == null) {
            throw new NoSuchCarInParkingLot();
        }
        return car;
    }
}

@@ -385,36 +385,8 @@
 e %7B%0A
-        UUID ticket = null;%0A
     
@@ -449,212 +449,93 @@
     
-try %7B%0A                ticket = parkingLot.park(car);%0A                break;%0A            %7D catch (NoAvailableParkingSpace noAvailableParkingSpace) %7B%0A                noAvailableParkingSpace.printStackTrace(
+if (parkingLot.getAvailableSpaces() %3E 0) %7B%0A                return parkingLot.park(car
 );%0A 
@@ -561,42 +561,8 @@
   %7D%0A
-        if (ticket == null) %7B%0A    
     
@@ -606,41 +606,8 @@
 ();%0A
-        %7D%0A        return ticket;%0A
     

refactor ParkingBoy.