package de.duehl.swing.ui.start.filter.project.method;

/*
 * Copyright 2020 Christian Dühl. All rights reserved.
 *
 * This program is free software. You can redistribute it and/or
 * modify it under the same terms as perl:
 *
 * general:  http://dev.perl.org/licenses/
 * GPL:      http://dev.perl.org/licenses/gpl1.html
 * artistic: http://dev.perl.org/licenses/artistic.html
 */

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

import de.duehl.basics.collections.CollectionsHelper;
import de.duehl.swing.ui.filter.method.Method;
import de.duehl.swing.ui.start.filter.project.data.TestFilterData;
import de.duehl.swing.ui.start.filter.project.gateway.generics.GenericData2Concrete;

/**
 * Diese Klasse repräsentiert die Filtermethode 'Datensätze mit den kritischen WZ-Codes'
 * (CRITICAL_CODES).
 *
 * @version 1.01     2020-11-05
 * @author Christian Dühl
 */

public class TestMethodCriticalCodes<Data> implements Method<Data> {

    /** Liste mit den kritischen Codes. */
    private static final List<String> criticalCodes = CollectionsHelper.buildListFrom("4713");

    @Override
    public List<Integer> buildFilter(List<Data> list) {
        List<Integer> indexList = new ArrayList<>();

        for (int index = 0; index < list.size(); ++index) {
            Data data = list.get(index);
            TestFilterData testFilterData = new GenericData2Concrete<Data>().generic2Concrete(data);

            boolean hasCriticalCodes = false;

            for (String code : testFilterData.getWzCodes()) {
                for (String criticalCode : criticalCodes) {
                    if (code.startsWith(criticalCode)) {
                        hasCriticalCodes = true;
                        break;
                    }
                }
                if (hasCriticalCodes) {
                    break;
                }
            }

            if (hasCriticalCodes) {
                indexList.add(index + 1);
            }
        }

        return indexList;
    }

}
