package com.yhy.module.core.enums.quota;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 取值规则枚举
 */
@Getter
@AllArgsConstructor
public enum RoundingRuleEnum {

    ROUND_UP(1, "round_up", "向上取整"),
    ROUND_DOWN(2, "round_down", "向下取整"),
    ROUND_HALF_UP(3, "round_half_up", "四舍五入"),
    NO_ROUNDING(4, "no_rounding", "不取整");

    private final Integer type;
    private final String code;
    private final String name;

    public static RoundingRuleEnum valueOf(Integer type) {
        return Arrays.stream(values())
                .filter(e -> e.getType().equals(type))
                .findFirst()
                .orElse(null);
    }

    public static RoundingRuleEnum valueOfCode(String code) {
        return Arrays.stream(values())
                .filter(e -> e.getCode().equals(code))
                .findFirst()
                .orElse(null);
    }
}
