package com.tzld.piaoquan.recommend.server.service.recall;

import com.tzld.piaoquan.recommend.server.model.Video;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;

/**
 * @author dyp
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RecallResult {
    private List<RecallData> data;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class RecallData {
        private String pushFrom;
        private List<Video> videos;
    }

    public List<Video> mergeRecallVideos() {
        if (CollectionUtils.isEmpty(data)) {
            return Collections.emptyList();
        }
        LinkedHashSet<Video> rankItems = new LinkedHashSet<>();
        for (int i = 0; i < data.size(); i++) {
            if (CollectionUtils.isEmpty(data.get(i).videos)) {
                continue;
            }
            for (int j = 0; j < data.get(i).videos.size(); j++)
                rankItems.add(data.get(i).videos.get(j));
        }
        return new ArrayList<>(rankItems);
    }

}
