package cn.axzo.msg.center.nimpush.device;

import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author yanglin
 */
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
public class PushDeviceSnapshots {

    private final Map<Long, PushDevice> cache = new ConcurrentHashMap<>();
    private final PushDeviceService pushDeviceService;

    public PushDevice getDevice(Long personId) {
        return cache.computeIfAbsent(personId, this::createDevice);
    }

    private PushDevice createDevice(Long personId) {
        return new PushDevice(pushDeviceService, personId);
    }

}