package com.greenorange.promotion.model.enums;

import com.greenorange.promotion.annotation.BaseEnum;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 试看权限枚举
 */
@Getter
public enum PreviewPermissionEnum implements BaseEnum {

    FULL_VIEW("全集试看"),
    PART_VIEW("部分试看"),
    CLOSED("关闭"),
    OPEN("开启");

    private final String value;

    PreviewPermissionEnum(String value) {
        this.value = value;
    }

    /**
     * BaseEnum 要求的方法：返回枚举对应的校验值
     */
    @Override
    public String getValue() {
        return this.value;
    }

    /**
     * 获取所有枚举值列表
     */
    public static List<String> getValues() {
        return Arrays.stream(values())
                     .map(PreviewPermissionEnum::getValue)
                     .collect(Collectors.toList());
    }

    /**
     * 根据值获取对应的枚举对象
     */
    public static PreviewPermissionEnum getEnumByValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (PreviewPermissionEnum permission : PreviewPermissionEnum.values()) {
            if (permission.value.equals(value)) {
                return permission;
            }
        }
        return null;
    }
}
