package com.pusong.common.translation.core.impl;

import com.pusong.common.core.service.DictService;
import com.pusong.common.core.utils.StringUtils;
import com.pusong.common.translation.annotation.TranslationType;
import com.pusong.common.translation.constant.TransConstant;
import com.pusong.common.translation.core.TranslationInterface;
import lombok.AllArgsConstructor;

/**
 * 字典翻译实现
 *
 * @author Lion Li
 */
@AllArgsConstructor
@TranslationType(type = TransConstant.DICT_TYPE_TO_LABEL)
public class DictTypeTranslationImpl implements TranslationInterface<String> {

    private final DictService dictService;

    @Override
    public String translation(Object key, String other) {
        if (key instanceof String dictValue && StringUtils.isNotBlank(other)) {
            String ret = dictService.getDictLabel(other, dictValue);
            return StringUtils.isBlank(ret)? dictValue:ret;
        }
        return null;
    }
}
