package com.yonge.cooleshow.biz.dal.service.impl;

import com.yonge.cooleshow.biz.dal.entity.AlbumFavorite;
import com.yonge.cooleshow.biz.dal.dao.AlbumFavoriteDao;
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import com.yonge.cooleshow.biz.dal.service.AlbumFavoriteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * AlbumFavoriteService服务实现类
 * @author yzp
 * @date 2022-03-26 00:01:37
 * @version v1.0
 **/
@Service
public class AlbumFavoriteServiceImpl extends ServiceImpl<AlbumFavoriteDao,AlbumFavorite> implements AlbumFavoriteService {

    private final static Logger log = LoggerFactory.getLogger(AlbumFavoriteServiceImpl.class);

    @Autowired
    private AlbumFavoriteDao albumFavoriteDao;

    public AlbumFavoriteDao getDao() {
        return albumFavoriteDao;
    }

    @Override
    public List<AlbumFavorite> getFavorite(Long studentId, Long albumId, ClientEnum clientType) {

        return this.lambdaQuery()
                    .eq(AlbumFavorite::getAlbumId, albumId)
                    .eq(AlbumFavorite::getUserId, studentId)
                    .eq(AlbumFavorite::getClientType, clientType)
                    .list();
    }

    @Override
    public List<Long> selectFavorite(Long userId, List<Long> albumIds, ClientEnum clientType) {

        List<AlbumFavorite> list = this.lambdaQuery()
                .in(AlbumFavorite::getAlbumId, albumIds)
                .eq(AlbumFavorite::getUserId, userId)
                .eq(AlbumFavorite::getClientType, clientType)
                .list();

        if (CollectionUtils.isEmpty(list)) {
            return new ArrayList<>();
        }
        return list.stream().map(AlbumFavorite::getAlbumId).collect(Collectors.toList());
    }
}