package com.engine.salary.enums.auth;

import com.engine.salary.enums.BaseEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.service.impl.SalaryEmployeeServiceImpl;

import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 资源类型，1：扣缴义务人  2：账套
 * <p>Copyright: Copyright (c) 2024</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public enum ResourceTargetTypeEnum implements BaseEnum<Integer> {


    TAX_AGENT(1, "扣缴义务人", 87627) {
        @Override
        public List<Long> getEmpIds(Set<String> targets) {
            return targets.stream().map(Long::valueOf).collect(Collectors.toList());
        }
    },
    SOB(2, "账套", 87626) {
        @Override
        public List<Long> getEmpIds(Set<String> targets) {
            List<Long> deptIds = targets.stream().map(Long::valueOf).collect(Collectors.toList());
            SalaryEmployeeServiceImpl salaryEmployeeService = new SalaryEmployeeServiceImpl();
            return salaryEmployeeService.listByDepartment(deptIds);
        }
    };


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

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

    public abstract List<Long> getEmpIds(Set<String> targets);


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

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

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

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