package com.ruoyi.common.utils;

import com.ruoyi.project.business.domain.TbArea;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.function.Function;
import java.util.function.Supplier;

import static com.ruoyi.common.constant.Constants.AREA_LOCAL_NAME_FUN;

/**
 * @author fangk
 * @date 2024/5/29
 * @desc LocalUtils 本地化获取区域、国家 getter 工具类
 */
public class LocalUtils {

    private static final Supplier<String> LOCAL = () -> {
        try {
            return LocaleContextHolder.getLocale().getCountry();
        } catch (Exception e) {
            return "";
        }
    };

    public static Function<TbArea, String> localAreaNameFun() {
        return AREA_LOCAL_NAME_FUN.getOrDefault(LOCAL.get(), TbArea::getAreaName);
    }

    public static Function<TbArea, String> localCountryNameFun() {
        return AREA_LOCAL_NAME_FUN.getOrDefault(LOCAL.get(), TbArea::getAreaName);


    }
}