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

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 会员积分业务类型，对应 {@code app_member_points_log.biz_type} 及积分变动来源。
 *
 * @author jeesharp
 * @since 2026-06-09
 */
@Getter
@AllArgsConstructor
public enum MemberPointsBizTypeEnum {

    CONSUME("CONSUME", "订单消费赠送"),
    REGISTER("REGISTER", "新会员注册"),
    ORDER_CANCEL("ORDER_CANCEL", "订单取消扣回"),
    SIGN_IN("SIGN_IN", "每日签到"),
    SHARE("SHARE", "分享获取"),
    INVITE("INVITE", "邀请好友"),
    BIRTHDAY("BIRTHDAY", "生日赠送"),
    UPGRADE("UPGRADE", "升级赠送"),
    EXCHANGE("EXCHANGE", "积分兑换"),
    COUPON_EXCHANGE("COUPON_EXCHANGE", "积分兑换优惠券"),
    REFUND("REFUND", "退款扣减"),
    MANUAL("MANUAL", "人工调整"),
    EXPIRE("EXPIRE", "积分到期清零"),
    ACTIVITY("ACTIVITY", "活动奖励");

    private final String code;

    private final String desc;

    public static MemberPointsBizTypeEnum fromCode(String code) {
        if (code == null || code.isBlank()) {
            return null;
        }
        for (MemberPointsBizTypeEnum item : values()) {
            if (item.getCode().equalsIgnoreCase(code.trim())) {
                return item;
            }
        }
        return null;
    }

    public static String getDescByCode(String code) {
        MemberPointsBizTypeEnum item = fromCode(code);
        return item != null ? item.getDesc() : "";
    }
}
