package com.eco.common.mapper.core.impl;

import com.eco.common.mapper.core.FieldMapperInterface;
import com.eco.common.mapper.annotation.FieldMapperType;
import com.eco.common.mapper.constant.MapperConstant;
import lombok.AllArgsConstructor;
import org.eco.common.core.service.UserService;

/**
 * @Description: NicknameMapperImpl
 * @Author: GaoKun Wang
 * @Date: 2024/7/1
 */
@AllArgsConstructor
@FieldMapperType(type = MapperConstant.USER_ID_TO_NICKNAME)
public class NicknameMapperImpl implements FieldMapperInterface<String> {

    private final UserService userService;

    @Override
    public String fieldMapper(Object key, String other) {
        if (key instanceof Long id) {
            return userService.selectNicknameByIds(id.toString());
        } else if (key instanceof String ids) {
            return userService.selectNicknameByIds(ids);
        }
        return null;
    }
}
