package org.dromara.common.translation.core.impl;

import com.hotwj.platform.resourceManagement.companySafetyManager.domain.HotCompanySafetyManager;
import com.hotwj.platform.resourceManagement.companySafetyManager.mapper.HotCompanySafetyManagerMapper;
import lombok.AllArgsConstructor;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.common.translation.annotation.TranslationType;
import org.dromara.common.translation.constant.TransConstant;
import org.dromara.common.translation.core.TranslationInterface;

/**
 * 安全管理人员名称翻译实现
 */
@AllArgsConstructor
@TranslationType(type = TransConstant.SAFETY_MANAGER_ID_TO_NAME)
public class SafetyManagerNameTranslationImpl implements TranslationInterface<String> {

    @Override
    public String translation(Object key, String other) {
        if (key instanceof Long id) {
            HotCompanySafetyManagerMapper mapper = SpringUtils.getBean(HotCompanySafetyManagerMapper.class);
            HotCompanySafetyManager entity = mapper.selectById(id);
            return entity != null ? entity.getName() : null;
        } else if (key instanceof String ids) {
            // 仅支持单个ID字符串
            try {
                Long id = Long.valueOf(ids);
                HotCompanySafetyManagerMapper mapper = SpringUtils.getBean(HotCompanySafetyManagerMapper.class);
                HotCompanySafetyManager entity = mapper.selectById(id);
                return entity != null ? entity.getName() : null;
            } catch (NumberFormatException ignored) {
            }
        }
        return null;
    }
}
