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

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

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

/**
 * 充值赠送类型枚举
 *
 * @author 晨丰科技
 */
@Getter
@AllArgsConstructor
public enum RechargeGiftTypeEnum implements IntArrayValuable {

    FULL_X_GIVE_X(0, "满X送X"),
    EVERY_X_GIVE_X(1, "每满X送X");

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

    /**
     * 状态值
     */
    private final Integer status;
    /**
     * 状态名
     */
    private final String name;

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

    /**
     * 是否满X送X
     *
     * @param name
     * @return
     */
    public static boolean isFullGive(String name) {
        return Objects.equals(FULL_X_GIVE_X.name, name);
    }

    /**
     * 是否每满X送X
     *
     * @param name
     * @return
     */
    public static boolean isEveryGive(String name) {
        return Objects.equals(EVERY_X_GIVE_X.name, name);
    }


    public static RechargeGiftTypeEnum fromStatus(Integer status) {
        for (RechargeGiftTypeEnum value : values()) {
            if (Objects.equals(value.status, status)) {
                return value;
            }
        }
        return null;
    }
}
