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.OssService;

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

    private final OssService ossService;

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