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

import com.google.common.collect.Lists;
import com.google.common.reflect.TypeToken;
import com.tzld.piaoquan.recommend.server.model.Video;
import com.tzld.piaoquan.recommend.server.service.filter.FilterResult;
import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
import com.tzld.piaoquan.recommend.server.util.DateUtils;
import com.tzld.piaoquan.recommend.server.util.JSONUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * 不区分地域小时（不做离线去重）
 *
 * @author dyp
 */
@Service
public class DahanRecallStrategy extends AbstractRegionRecallStrategy {
    public static final String PUSH_FORM = "dahan_recall";

    @Override
    public List<Video> recall(RecallParam param) {
        List<Video> results = new ArrayList<>();

        List<Long> ss = new ArrayList<>(Arrays.asList(10409992L, 10436156L, 18160019L, 18247521L, 18254840L));
        ss.stream().forEach(vid -> {
            Video video = new Video();
            video.setVideoId(vid);
            video.setAbCode(param.getAbCode());
            video.setRovScore(Math.random());
            video.setPushFrom(pushFrom());
            video.setLastVideoKey("zhangbo");
            results.add(video);
        });



        Collections.sort(results, Comparator.comparingDouble(o -> -o.getRovScore()));

        return results;
    }
    @Override
    protected String recordKey(RecallParam param) {
        return String.format("recall:last:record:h:%s:%s", param.getAppType(), param.getMid());
    }

    @Override
    protected String poolKey(RecallParam param, String now_dt, int h) {
        // hard code  因为生产任务，会给region填充默认值-1
        return String.format("recall:item:score:h:%s:%s:%s:%s",
                param.getDataKey(), param.getRuleKey(), now_dt, h);
    }

    @Override
    protected String lastVideoKey(RecallParam param) {
        return String.format("LAST_VIDEO_KEY_FORMAT", param.getAppType(), param.getMid());
    }

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