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

import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

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

/**
 * 用户历史分享视频的社交I2I召回
 */
@Slf4j
@Component
public class SocialI2IHistoryClickRecallStrategy extends SocialI2IBasicRecallStrategy {

    public static final String PUSH_FROM = "social_i2i_history_click_recall";

    @Override
    protected List<Long> genLeftItemList(RecallParam param) {
        if (MapUtils.isEmpty(param.getUserSocialRecallInfo())) {
            return new ArrayList<>();
        }
        String clickVidList = param.getUserSocialRecallInfo().getOrDefault("click_vids", "");
        return Arrays.stream(clickVidList.split(","))
                .map(String::trim)
                .filter(StringUtils::isNotBlank)
                .map(Long::valueOf)
                .collect(Collectors.toList());
    }

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