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

import com.tzld.piaoquan.recommend.server.service.rank.bo.UserSRBO;
import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class Return1Cate2RosRecallStrategy extends AbstractRedisRecallStrategy {
    private static final int keysN = 2;
    private static final int topN = 80;
    public static final String PUSH_FORM = "return_1_cate2_ros";
    private static final String redisKeyPrefix = "return_1_cate2_recall";

    @Override
    public String pushFrom() {
        return PUSH_FORM;
    }

    @Override
    protected List<String> getRedisKeys(RecallParam param) {
        List<String> keys = new ArrayList<>();
        if (null != param && null != param.getBehaviorVideos() && null != param.getUserProfile()) {
            Map<String, Map<String, String>> behaviorVideos = param.getBehaviorVideos();
            List<UserSRBO> l_r1_s = param.getUserProfile().getL_r1_s();
            if (null != l_r1_s) {
                for (UserSRBO u : l_r1_s) {
                    if (null != u) {
                        String vid = String.valueOf(u.getId());
                        if (behaviorVideos.containsKey(vid)) {
                            String cate2 = behaviorVideos.get(vid).getOrDefault("merge_second_level_cate", "");
                            if (null != cate2 && !cate2.isEmpty()) {
                                keys.add(String.format("%s:%s:%s", redisKeyPrefix, cate2, "ros"));
                                if (keys.size() >= keysN) {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        return keys;
    }

    @Override
    protected int getTopN() {
        return topN;
    }
}