package com.starry.admin.modules.order.module.constant;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * Resolves human-readable labels for order scenarios used in notifications.
 */
@Slf4j
public final class OrderMessageLabelResolver {

    private OrderMessageLabelResolver() {
    }

    public static String resolve(String placeTypeCode, String rewardTypeCode) {
        OrderConstant.PlaceType placeTypeEnum = OrderConstant.PlaceType.RANDOM;
        if (StringUtils.isNotBlank(placeTypeCode)) {
            try {
                placeTypeEnum = OrderConstant.PlaceType.fromCode(placeTypeCode);
            } catch (IllegalArgumentException ex) {
                log.warn("未知的下单类型，placeTypeCode={}，按随机单处理。", placeTypeCode, ex);
            }
        }
        switch (placeTypeEnum) {
            case SPECIFIED:
                return "指定单";
            case REWARD:
                OrderConstant.RewardType rewardTypeEnum = OrderConstant.RewardType.BALANCE;
                if (StringUtils.isNotBlank(rewardTypeCode)) {
                    try {
                        rewardTypeEnum = OrderConstant.RewardType.fromCode(rewardTypeCode);
                    } catch (IllegalArgumentException ex) {
                        log.warn("未知的打赏类型，rewardTypeCode={}，按打赏处理。", rewardTypeCode, ex);
                    }
                }
                return rewardTypeEnum == OrderConstant.RewardType.GIFT ? "礼物" : "打赏";
            case RANDOM:
            default:
                return "随机单";
        }
    }
}
