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) -> {

            String legalBaseStr = row.getAs("LEGAL_BASE", String.class);

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

            if (legalBaseStr == null || legalBaseStr.isEmpty()) {
                return;
            }

			LegalBase legalBase = new LegalBase(legalBaseStr,
					row.getAs("OFF_JOURNAL", String.class), row.getAs("PAGE", Integer.class),
					row.getAs("PUBL_DATE", LocalDate.class));
			legalBases.add(legalBase);

		});

		return legalBases;

	}
}
