import java.util.ArrayList;
import java.util.List;

/** Lee una lista de precios con líneas de la forma "código;precio". */
public class PriceReader {

    public static List<Money> read(List<String> lines) throws InvalidPriceException {
        List<Money> prices = new ArrayList<>();
        for (int i = 0; i < lines.size(); i++) {
            String[] fields = lines.get(i).split(";");
            String price = fields.length == 2 ? fields[1] : "";
            try {
                prices.add(Money.parse(price));
            } catch (NumberFormatException e) {
                // Se envuelve el error de bajo nivel en uno del dominio, sin perderlo.
                throw new InvalidPriceException(i + 1, price, e);
            }
        }
        return prices;
    }
}
