package de.avatic.taricdb.helper.workbook.converters;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;

import de.avatic.taricdb.helper.workbook.ExcelTable;
import de.avatic.taricdb.model.LegalBase;
import de.avatic.taricdb.service.ReferenceStorageService;

public class LegalBaseConverter implements ExcelTableConverter<LegalBase> {

	public LegalBaseConverter(ReferenceStorageService referenceStorage) {
	}

	@Override
	public Collection<LegalBase> convert(ExcelTable table) {
		Collection<LegalBase> legalBases = new ArrayList<>();

		table.getRows().forEach((row) -> {

			if (row.index() == 0) {
				return;
			}

			LegalBase legalBase = new LegalBase(row.getAs("Legal base", String.class),
					row.getAs("Off. Journal", String.class), row.getAs("Page", Integer.class),
					row.getAs("Publ. date", LocalDate.class));
			legalBases.add(legalBase);

		});

		return legalBases;

	}
}
