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

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.*;

@Slf4j
@Service
public class PredictStrategyBy667 extends ThresholdPredictStrategy {
    @Override
    Map<String, Double> thresholdConfig(PredictContext ctx) {
        try {
            JSONObject json = ctx.getExpConfigMap().getOrDefault("667", new JSONObject());
            return json.toJavaObject(new TypeReference<Map<String, Double>>() {
            });
        } catch (Exception e) {
            log.error("PredictStrategyBy667 parse 667 exp param error \n", e);
            return Collections.emptyMap();
        }
    }

    @Override
    List<String> genThresholdKeys(PredictContext ctx) {
        List<String> keys = new ArrayList<>();
        for (String appType : Arrays.asList(ctx.getAppType(), "default")) {
            for (String userLayer : Arrays.asList(ctx.getUserLayer(), "default")) {
                keys.add(String.join("_", appType, userLayer, ctx.getHandleAfterShareType()));
            }
        }
        keys.add("default_threshold");
        return keys;
    }

    @Override
    public String name() {
        return "667";
    }

}
