package cn.axzo.msg.center.inside.notices.service.impl.v3.msg;

import cn.axzo.im.center.common.enums.AppTypeEnum;
import cn.axzo.msg.center.service.enums.PushTerminalEnum;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

import static java.util.stream.Collectors.toList;

/**
 * @author yanglin
 */
@Component
public class TerminalAppMapping {

    private final ImmutableMap<PushTerminalEnum, AppTypeEnum> terminal2AppType = ImmutableMap.of(
            PushTerminalEnum.B_ENTERPRISE_APP, AppTypeEnum.CMP,
            PushTerminalEnum.C_WORKER_APP, AppTypeEnum.CM
    );

    public List<AppTypeEnum> toImTypes(List<PushTerminalEnum> terminals) {
        if (CollectionUtils.isEmpty(terminals)) {
            return Collections.emptyList();
        }
        return terminals.stream()
                .map(this::toImType)
                .distinct()
                .collect(toList());
    }

    public AppTypeEnum toImType(PushTerminalEnum terminal) {
        return terminal2AppType.get(terminal);
    }

}