package com.ruoyi.common.utils.translation;

import com.ruoyi.common.core.domain.BaseEntity;

import java.util.List;
import java.util.Map;

/**
 * zhao: 字段自动字典翻译
 * 需要翻译的字段必须使用Translate注解或Excel注解标记
 * 优先级:
 *     注解: Translate优先级大于Excel. 只会使用Translate或Excel其中的一种, 不会混合
 *     注解属性: readConverterExp优先级大于dictType. readConverterExp和dictType的键值对最终会混合在一起
 * 字段类型:
 *     如果是String类型, 必须赋值注解的dictType或readConverterExp
 *     如果是其他复合类型/List, 无需赋值dictType或readConverterExp, 仅标记注解即可, 此时将递归翻译(注意不要循环嵌套对象)
 *
 * 数据库表数据字典: 仅Translate注解支持
 *     字段必须为String类型
 */
public final class TranslateUtils
{
    private TranslateUtils() {}

    public static void translateList(List<?> list, Object...args)
    {
        new Translator().translateList(list, args);
    }

    public static void translate(Object obj, Object...args)
    {
        new Translator().translate(obj, args);
    }

    public static void translateMapList(List<Map<String, Object>> list, Map<String, String> dictMap)
    {
        new Translator().translateMapList(list, dictMap);
    }

    public static void translateMap(Map<String, Object> map, Map<String, String> dictMap)
    {
        new Translator().translateMap(map, dictMap);
    }

    public static <T> void translateObjectList(List<T> list)
    {
        new Translator().translateObjectList(list);
    }

    public static <T> void translateObject(T object)
    {
        new Translator().translateObject(object);
    }

    public static <T extends BaseEntity> void translateEntityList(List<T> list, boolean...keepRawField)
    {
        boolean b = null != keepRawField && keepRawField.length > 0 ? keepRawField[0] : false;
        new Translator().translateEntityList(list, b);
    }

    public static <T extends BaseEntity> void translateEntity(T object, boolean...keepRawField)
    {
        boolean b = null != keepRawField && keepRawField.length > 0 ? keepRawField[0] : false;
        new Translator().translateEntity(object, b);
    }
}
