package org.academiadecodigo.bootcamp.car;

import org.academiadecodigo.bootcamp.grid.Grid;

/**
 * A factory of different types of Cars
 */
public class CarFactory {

    /**
     * Manufactures new random cars
     *
     * @return a newly instantiated car
     */
    public static Car getNewCar(Grid grid) {

        int random = (int) (Math.random() * CarType.values().length);
        CarType carType = CarType.values()[random];

        Car car;

        switch (carType) {
            case FIAT:
                car = new Fiat(grid.makeGridPosition());
                break;
            case MUSTANG:
                car = new Mustang(grid.makeGridPosition());
                break;
            case TELEPORTER:
                car = new Teleporter(grid.makeGridPosition());
                break;
            case TANK:
                car = new Tank(grid.makeGridPosition());
                break;
            default:
                car = new Fiat(grid.makeGridPosition());
        }

        return car;

    }

}
