package com.czg.constants;

import com.czg.account.entity.ShopInfo;
import com.czg.utils.SerializableFunction;

/**
 * 店铺 开关枚举
 *
 * @author ww
 */
public enum ShopSwitchTypeEnum {
    GROUP_BUY("拼团开关", ShopInfo::getIsGroupBuy),
   ;

    private final String description;
    private final SerializableFunction<ShopInfo, Integer> getter;

    ShopSwitchTypeEnum(String description,
                       SerializableFunction<ShopInfo, Integer> getter) {
        this.description = description;
        this.getter = getter;
    }

    public String getDescription() {
        return description;
    }

    public boolean getValue(ShopInfo shopInfo) {
        if (shopInfo == null) {
            return false;
        }
        try {
            return getter.apply(shopInfo) == 1;
        } catch (Exception e) {
            return false;
        }
    }

    public SerializableFunction<ShopInfo, Integer> getGetter() {
        return getter;
    }
}
