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

import com.tzld.piaoquan.ad.engine.service.predict.container.RandWContainer;
import lombok.Data;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public abstract class BasicPredict {

    public abstract Map<String, Object> predict(PredictContext ctx);

    public abstract String name();

    protected Map<String, Object> rtnNoAdPredict(PredictContext ctx) {
        Map<String, Object> rtnMap = new HashMap<>();
        rtnMap.put("ad_predict", 1);
        rtnMap.put("pqtId", ctx.getPqtId());
        return rtnMap;
    }

    protected Map<String, Object> rtnAdPredict(PredictContext ctx) {
        Map<String, Object> rtnMap = new HashMap<>();
        rtnMap.put("ad_predict", 2);
        if (ctx != null) {
            if( ctx.getLogParam() != null){
                rtnMap.putAll(ctx.getLogParam().getScoreMap());
            }
            rtnMap.put("pqtId", ctx.getPqtId());
        }
        return rtnMap;
    }


    protected double calcScoreByMid(String mid) {
        int hash = mid.hashCode();
        hash = hash < 0 ? -hash : hash;
        return (hash + RandWContainer.getRandW()) % 100 / 100d;
    }

    @Data
    protected static class RootSessionIdTailConfigItem {
        private Set<String> appType = new HashSet<>();
        private Set<String> tail = new HashSet<>();
        private Map<String, Double> config = new HashMap<>();
    }
}
