package cn.lihongjie.coal.common;


import io.vavr.Function3;

import lombok.experimental.UtilityClass;

import org.apache.poi.ss.formula.functions.T;

import java.util.*;
import java.util.function.Function;

@UtilityClass
public class ArchiveUtils {
    public static <T, E> void checkArchiveStatus(Function<Iterable<T>, Iterable<E>> mapper, Iterable<T> ids, Function<E, String> statusGetter, Function<E, String> expectedStatusGetter, Function3<E, String, String, Void> handler) {

        mapper.apply(ids)
                .forEach(
                        e -> {
                            String actual = statusGetter.apply(e);
                            String expected = expectedStatusGetter.apply(e);
                            if (!Objects.equals(actual, expected)) {

                                handler.apply(e, actual, expected);
                            }
                        });
    }

    public static <T, E> void checkArchiveStatus(E entity,  Function<E, String> statusGetter, Function<E, String> expectedStatusGetter, Function3<E, String, String, Void> handler) {


        checkArchiveStatus(
                x -> Collections.singletonList(entity),
                Collections.singletonList(entity),
                statusGetter,
                expectedStatusGetter,
                handler);
    }




}
