package com.tzld.piaoquan.ad.engine.service.predict.container;

import com.alibaba.fastjson.JSONObject;
import com.tzld.piaoquan.ad.engine.commons.feign.longvideo.abtest.LongVideoFeign;
import com.tzld.piaoquan.ad.engine.service.predict.impl.PredictModelServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class AbTestConfigContainer {
    private final static Logger log = LoggerFactory.getLogger(PredictModelServiceImpl.class);
    @Autowired
    LongVideoFeign longVideoFeign;
    @Value("${ad.abtest.time.plan.code:555}")
    String adTestCode;


    public Boolean containsCode(Map<String,List<JSONObject>> configMap,String code){
        return configMap.keySet().contains(code);
    }

    public Boolean inWithoutAdTime(Map<String,List<JSONObject>> abConfigMap,String code,Integer hourOfDay){
        Boolean flag=false;
        for(JSONObject object:abConfigMap.getOrDefault(code,new ArrayList<>())){
            if(object.getInteger("x")<=hourOfDay&&hourOfDay<object.getInteger("y")){
                return true;
            }
        }
        //
        return flag;
    }

    public Boolean inAdTimeTest(JSONObject abExpInfo){
        //todo youhua
        List<Map<String,Object>> mapList=(List)abExpInfo.get("ab_test002");
        for(Map<String,Object> map:mapList){
            if(adTestCode.equals(map.getOrDefault("abExpCode",""))){
                return true;
            }
        }
        //
        return false;
    }

}
