package com.engine.salary.enums.salaryarchive;

import com.engine.salary.enums.BaseEnum;
import com.engine.salary.util.SalaryI18nUtil;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 薪资档案-薪资项目调整原因
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public enum SalaryArchiveItemAdjustReasonEnum implements BaseEnum<String> {

    ONBOARD("ONBOARD", "入职", 85901),
    PROBATION_REVIEW("PROBATION_REVIEW", "转正", 85984),
    SALARY_ADJUSTMENT("SALARY_ADJUSTMENT", "调薪", 85985),
    PROMOTION("PROMOTION", "晋升", 85985),
    DEMOTION("DEMOTION", "降职", 85985),
    JOB_TRANSFER("JOB_TRANSFER", "调岗", 85985),
    POSITION_OR_SALARY_ADJUSTMENT("POSITION_OR_SALARY_ADJUSTMENT", "调岗调薪", 85986),
    DIMISSION("DIMISSION", "离职", 85902),
    OTHER("OTHER", "其他", 84500),
    INIT("INIT", "初始化", 85903);

    private String value;

    private String defaultLabel;

    private int labelId;

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

    public String getValue() {
        return value;
    }

    public String getDefaultLabel() {
        return defaultLabel;
    }

    public Integer getLabelId() {
        return labelId;
    }

    public static String getValueByDefaultLabel(String defaultLabel) {
        if (defaultLabel == null) {
            return "";
        }
        SalaryArchiveItemAdjustReasonEnum[] enumAry = SalaryArchiveItemAdjustReasonEnum.values();
        for(int i = 0; i < Arrays.asList(enumAry).size(); i++){
            if (enumAry[i].getDefaultLabel().equals(defaultLabel)) {
                return enumAry[i].getValue();
            }
        }
        return "";
    }
    public static String getDefaultLabelByValue(String value) {
        Optional<SalaryArchiveItemAdjustReasonEnum> optionalAdjustReason = Arrays.stream(SalaryArchiveItemAdjustReasonEnum.values()).filter(r->r.getValue().equals(value)).findFirst();
        return optionalAdjustReason.isPresent()? SalaryI18nUtil.getI18nLabel(optionalAdjustReason.get().getLabelId(), optionalAdjustReason.get().getDefaultLabel()):"";
    }

    public static SalaryArchiveItemAdjustReasonEnum parseByValue(String value) {
        for (SalaryArchiveItemAdjustReasonEnum optionalAdjustReason : SalaryArchiveItemAdjustReasonEnum.values()) {
            if (Objects.equals(optionalAdjustReason.getValue(), value)) {
                return optionalAdjustReason;
            }
        }
        return null;
    }

    public static List<Map<String, String>> getList(){
        return Arrays.stream(SalaryArchiveItemAdjustReasonEnum.values()).map(e -> {
            Map<String, String> map = new HashMap<>();
            map.put("id", e.getValue());
            map.put("content", e.getDefaultLabel());
            return map;
        }).collect(Collectors.toList());
    }
}
