package com.tzld.piaoquan.ad.engine.server.controller;

import com.tzld.piaoquan.ad.engine.commons.param.RankRecommendRequestParam;
import com.tzld.piaoquan.ad.engine.commons.score.ScoreParam;
import com.tzld.piaoquan.ad.engine.service.log.LogHubService;
import com.tzld.piaoquan.ad.engine.service.score.convert.RequestConvert;
import com.tzld.piaoquan.ad.engine.service.score.strategy.FeaturePrinterStrategy;
import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdRankItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/log")
public class LogUploadController {

    @Autowired
    private FeaturePrinterStrategy featurePrinterStrategy;

    @Autowired
    private LogHubService logHubService;

    @RequestMapping("/printFeatureOnly")
    public Map<String, Object> printFeatureOnly(@RequestBody RankRecommendRequestParam request) {
        ScoreParam scoreParam = RequestConvert.requestConvert(request);
        List<AdRankItem> adRankItems = featurePrinterStrategy.adItemRank(request, scoreParam);
        logHubService.scoreLogUpload(scoreParam, request.getAdIdList(), adRankItems, request, scoreParam.getExpCode());
        return new HashMap<String, Object>() {{
            put("result", "success");
        }};
    }


}
