package com.engine.salary.enums;

import com.engine.salary.entity.hrm.HrmStatus;

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

/**
 * 人员状态
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public enum UserStatusEnum implements BaseEnum {

    TRIAL(0, "试用", 1),
    FORMAL(1, "正式", 1),
    TEMPORARY(2, "临时", 1),
    DELAY(3, "试用延期", 1),
    FIRE(4, "解雇", 1),
    DEPARTURE(5, "离职", 1),
    RETIRED(6, "退休", 1),
    INVALID(7, "无效", 1);

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


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

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

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

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

    public static String getDefaultLabelByValue(Integer value) {
        Optional<UserStatusEnum> optional = Arrays.stream(UserStatusEnum.values()).filter(r -> r.getValue().equals(value)).findFirst();
        return optional.isPresent() ? optional.get().defaultLabel : "";
    }

    public static List<Map<String, String>> getList() {
        return Arrays.stream(UserStatusEnum.values())
                .filter(v -> v != INVALID)
                .map(v -> {
                    Map<String, String> m = new HashMap();
                    m.put("id", v.value.toString());
                    m.put("content", v.defaultLabel);
                    return m;
                }).collect(Collectors.toList());
    }

    /**
     * 在职状态
     *
     * @return
     */
    public static List<String> getNormalStatus() {
        return Arrays.asList(TRIAL.getValue().toString(), FORMAL.getValue().toString(), TEMPORARY.getValue().toString(), DELAY.getValue().toString());
    }

    /**
     * 离职状态
     *
     * @return
     */
    public static List<String> getUnavailableStatus() {
        return Arrays.asList(FIRE.getValue().toString(), DEPARTURE.getValue().toString(), RETIRED.getValue().toString());
    }

    /**
     * 全部状态
     *
     * @return
     */
    public static List<String> getAllStatus() {
        return Arrays.asList(TRIAL.getValue().toString(), FORMAL.getValue().toString(), TEMPORARY.getValue().toString(), DELAY.getValue().toString(),FIRE.getValue().toString(), DEPARTURE.getValue().toString(), RETIRED.getValue().toString());
    }

    public static List<UserStatusEnum> getEffectiveList() {
        return Arrays.stream(UserStatusEnum.values()).filter(v -> v != INVALID).collect(Collectors.toList());
    }

    public static List<HrmStatus> getHrmStatusList() {
        return Arrays.stream(UserStatusEnum.values())
                .filter(v -> v != INVALID)
                .map(v -> HrmStatus.builder().id(v.value.toString()).name(v.defaultLabel).build()).collect(Collectors.toList());
    }

    public static UserStatusEnum parseByValue(Integer value) {
        for (UserStatusEnum statusEnum : UserStatusEnum.values()) {
            if (Objects.equals(statusEnum.getValue(), value)) {
                return statusEnum;
            }
        }
        return null;
    }

}
