package com.cf.imes.module.system.enums.pay;

import com.cf.imes.framework.common.core.IntArrayValuable;
import com.cf.imes.framework.excel.core.convert.BaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

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

/**
 * 时长单位态枚举
 *
 * @author 晨丰科技
 */
@Getter
@AllArgsConstructor
public enum DurationUnitEnum implements IntArrayValuable, BaseEnum {

    YEAR(0, "duration.unit.year"),
    MONTH(1, "duration.unit.month"),
    DAY(2, "duration.unit.day");

    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DurationUnitEnum::getCode).toArray();

    /**
     * 状态值
     */
    private final Integer code;
    /**
     * 状态名
     */
    private final String desc;

    @Override
    public int[] array() {
        return ARRAYS;
    }

    public static DurationUnitEnum fromStatus(Integer status) {
        return Arrays.stream(values())
                .filter(bean -> Objects.equals(bean.code, status))
                .findFirst()
                .orElse(null);
    }

    /**
     * 获取描述desc，否则返回null
     *
     * @param status
     * @return
     */
    public static String getDesc(Integer status) {
        DurationUnitEnum unit = fromStatus(status);
        return unit != null ? unit.getDesc() : null;
    }
}
