package cn.reghao.tnb.content.app.vod.service;

import cn.reghao.jutil.jdk.db.PageList;
import cn.reghao.tnb.content.api.dto.VideoCard;
import cn.reghao.tnb.content.app.ContentApplication;
import cn.reghao.tnb.search.api.iface.DataSearchService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @author reghao
 * @date 2025-04-02 16:10:18
 */
@Slf4j
@ActiveProfiles("dev")
@SpringBootTest(classes = ContentApplication.class)
public class SearchTest {
    @DubboReference(check = false)
    DataSearchService dataSearchService;
    @Autowired
    SearchService searchService;
    @Test
    public void searchTest() {
        /*long userId = 10002L;
        String itemsKey = RedisKeys.getUserItemKey(userId);
        List<VideoCard> videoCards = new ArrayList<>();
        List<Object> list = redisSet.spop(itemsKey, 12);
        for (Object obj : list) {
            if (obj instanceof VideoCard) {
                videoCards.add((VideoCard) obj);
            }
        }*/

        /*List<VideoPost> list1 = videoPostMapper.findAll();
        int i = 1;
        for (VideoPost videoPost : list1) {
            String videoId = videoPost.getVideoId();
            String title = videoPost.getTitle();
            boolean vip = false;
            int scope = videoPost.getScope();
            if (scope == PostScope.PROTECT.getCode()) {
                vip = true;
            }

            VideoSummary videoSummary = new VideoSummary(videoId, title, vip);
            try {
                dataSearchService.addVideoSummary(videoSummary);
                log.info("add {} doc", i++);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }*/

        int pn = 1;
        String kw = "隔壁";
        /*PageList<VideoSummary> pageList = dataSearchService.searchVideo(kw, "", pn);
        Map<String, List<VideoSummary>> map = pageList.getList().stream()
                .collect(Collectors.groupingBy(VideoSummary::getVideoId));*/

        PageList<VideoCard> pageList1 = searchService.searchByKeyword(kw, "", pn);
        System.out.println();
    }
}
