package cn.pluss.platform.user;

import cn.pluss.platform.entity.UserPushId;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author djh
 */
public interface UserPushIdService extends IService<UserPushId> {

    void setCid(Long userId, String cid);

    void apiSetCid(String cid);

    default UserPushId getByUserId(Long userId) {

        LambdaQueryWrapper<UserPushId> qWrapper = Wrappers.lambdaQuery();
        qWrapper.eq(UserPushId::getUserId, userId);

        return getBaseMapper().selectOne(qWrapper);
    }

    default List<String> getGetuiCidListByUserIds(Long... userId) {
        LambdaQueryWrapper<UserPushId> qWrapper = Wrappers.lambdaQuery();
        qWrapper.in(UserPushId::getUserId, Arrays.asList(userId));

        List<UserPushId> items = getBaseMapper().selectList(qWrapper);

        List<String> cidList = new ArrayList<>();
        for (UserPushId item : items) {
            cidList.add(item.getGetuiClientId());
        }

        return cidList;
    }
}