package com.engine.salary.enums;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

/**
 * 账号类型
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public enum AccountTypeEnum implements BaseEnum {

    MAIN(0, "主账号", 1),
    SECOND(1, "次账号", 1);

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


    AccountTypeEnum(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) {
        if (value == null) {
            return MAIN.defaultLabel;
        }
        Optional<AccountTypeEnum> optional = Arrays.stream(AccountTypeEnum.values()).filter(r -> r.getValue().equals(value)).findFirst();
        return optional.isPresent() ? optional.get().defaultLabel : "";
    }


    public static AccountTypeEnum parseByValue(Integer value) {
        if (value == null) {
            return MAIN;
        }

        for (AccountTypeEnum statusEnum : AccountTypeEnum.values()) {
            if (Objects.equals(statusEnum.getValue(), value)) {
                return statusEnum;
            }
        }
        return MAIN;
    }

}
