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, "年"),
    MONTH(1, "月"),
    DAY(2, "日");

    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 boolean isYear(String name) {
        return Objects.equals(YEAR.code, name);
    }

    public static boolean isMonth(String name) {
        return Objects.equals(MONTH.code, name);
    }

    public static boolean isDay(String name) {
        return Objects.equals(DAY.code, name);
    }

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