package com.face.util;


import com.face.util.spring.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.Nullable;

import java.util.Locale;

@Slf4j
public class MessageUtils {
    public static String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) {
        try {
            return SpringUtils.getMessageSource().getMessage(code, args, defaultMessage, locale);
        } catch (Exception e) {
            log.warn("getMessageFail {} {}", code, args, e);
        }
        return defaultMessage;
    }

    public static  String getMessage(String code, @Nullable Object[] args, Locale locale) {
        try {
            return SpringUtils.getMessageSource().getMessage(code, args, locale);
        } catch (Exception e) {
            log.warn("getMessageFail {} {}", code, args, e);
        }
        return code;
    }

    public static  String getMessageReturnNull(String code, @Nullable Object[] args, Locale locale) {
        try {
            return SpringUtils.getMessageSource().getMessage(code, args, locale);
        } catch (Exception e) {
            log.warn("getMessageFail {} {}", code, args, e);
        }
        return null;
    }

}
