package com.engine.salary.enums.auth;

import cn.hutool.core.collection.CollectionUtil;
import com.engine.salary.enums.BaseEnum;
import com.engine.salary.exception.SalaryRunTimeException;

import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * 或者、并且、排除
 * <p>Copyright: Copyright (c) 2024</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public enum DataLinkEnum implements BaseEnum<Integer> {


    OR(1, "并集运算", 87627) {
        @Override
        public Set<Long> calculation(Collection<Long> coll1, Collection<Long> coll2) {
            return new HashSet<>(CollectionUtil.union(coll1, coll2));
        }
    },
    AND(2, "交集运算", 87626) {
        @Override
        public Set<Long> calculation(Collection<Long> coll1, Collection<Long> coll2) {
            return new HashSet<>(CollectionUtil.intersection(coll1, coll2));
        }
    },
    NOT_IN(3, "补集运算", 87626) {
        @Override
        public Set<Long> calculation(Collection<Long> coll1, Collection<Long> coll2) {
            return new HashSet<>(CollectionUtil.disjunction(coll1, coll2));
        }
    };


    private Integer value;
    private String defaultLabel;
    private int labelId;

    DataLinkEnum(Integer value, String defaultLabel, int labelId) {
        this.value = value;
        this.defaultLabel = defaultLabel;
        this.labelId = labelId;
    }

    public abstract Set<Long> calculation(Collection<Long> coll1, Collection<Long> coll2);


    @Override
    public Integer getValue() {
        return value;
    }

    @Override
    public String getDefaultLabel() {
        return defaultLabel;
    }

    @Override
    public Integer getLabelId() {
        return labelId;
    }

    public static DataLinkEnum parseByValue(int value) {
        for (DataLinkEnum typeEnum : DataLinkEnum.values()) {
            if (Objects.equals(typeEnum.getValue(), value)) {
                return typeEnum;
            }
        }
        throw new SalaryRunTimeException("未找到对应的枚举");
    }
}
