package com.jeesharp.business.modules.member.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 会员积分流水类型，对应 {@code app_member_points_log.points_type}。
 *
 * @author jeesharp
 * @since 2026-06-09
 */
@Getter
@AllArgsConstructor
public enum MemberPointsTypeEnum {

    /**
     * 获取
     */
    EARN(1, "获取", "earn"),

    /**
     * 消费
     */
    SPEND(2, "消费", "spend"),

    /**
     * 冻结
     */
    FREEZE(3, "冻结", "adjust"),

    /**
     * 解冻
     */
    UNFREEZE(4, "解冻", "adjust"),

    /**
     * 过期
     */
    EXPIRE(5, "过期", "expire"),

    /**
     * 调整
     */
    ADJUST(6, "调整", "adjust");

    private final Integer value;

    private final String desc;

    /**
     * 小程序积分记录 tab 分类键
     */
    private final String changeTypeKey;

    public static MemberPointsTypeEnum fromValue(Integer value) {
        if (value == null) {
            return null;
        }
        for (MemberPointsTypeEnum item : values()) {
            if (item.getValue().equals(value)) {
                return item;
            }
        }
        return null;
    }

    public static String getDescByValue(Integer value) {
        MemberPointsTypeEnum item = fromValue(value);
        return item != null ? item.getDesc() : "";
    }

    public static String getChangeTypeKey(Integer value) {
        MemberPointsTypeEnum item = fromValue(value);
        return item != null ? item.getChangeTypeKey() : "adjust";
    }
}
