package examples.dataloader;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.tzld.piaoquan.recommend.feature.domain.video.feature.BytesGroup;
import com.tzld.piaoquan.recommend.feature.domain.video.feature.BytesUtils;
import com.tzld.piaoquan.recommend.feature.model.sample.BaseFeature;
import com.tzld.piaoquan.recommend.feature.model.sample.FeatureGroup;

import java.util.Map;

public class OfflineVlogShareLRFeatureExtractorV2 {

    public ListMultimap<FeatureGroup, BaseFeature> featureMap = ArrayListMultimap.create();

    final private BytesUtils utils;
    final private int groupCount = OfflineVlogFeatureGroupV2.values().length;
    public OfflineVlogShareLRFeatureExtractorV2() {
        BytesGroup[] groups = new BytesGroup[OfflineVlogFeatureGroupV2.values().length];
        OfflineVlogFeatureGroupV2[] var2 = OfflineVlogFeatureGroupV2.values();
        int var3 = var2.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            OfflineVlogFeatureGroupV2 g = var2[var4];
            groups[g.ordinal()] = new BytesGroup(g.ordinal(), g.getGroupName(), g.getGroupNameBytes());
        }
        this.utils = new BytesUtils(groups);
    }
    public void makeFeature(Map<String, Object> maps){
        for (Map.Entry<String, Object> entry : maps.entrySet()){
            OfflineVlogFeatureGroupV2 ovf = OfflineVlogFeatureGroupV2.valueOf(entry.getKey());
            Object value = entry.getValue();
            if (value instanceof String){
                this.makeFea(ovf, ((String)value).getBytes());
            }else if (value instanceof Double){
                this.makeFea(ovf, String.valueOf((Double)value).getBytes());
            }else if (value instanceof Integer){
                //todo
            }else{
                //todo
                this.makeFea(ovf, ((String)value).getBytes());
            }
        }
    }
    public void makeFeature4String(Map<String, String> maps){
        for (Map.Entry<String, String> entry : maps.entrySet()){
            OfflineVlogFeatureGroupV2 ovf = OfflineVlogFeatureGroupV2.valueOf(entry.getKey());
            String value = entry.getValue();
            this.makeFea(ovf, value.getBytes());
        }
    }

    private FeatureGroup makeGroup(OfflineVlogFeatureGroupV2 group) {
        FeatureGroup.Builder g = FeatureGroup.newBuilder();
        g.setType("1");
        g.setName(group.getGroupName());
        g.setId(group.ordinal());
        return g.build();
    }
    void makeFea(OfflineVlogFeatureGroupV2 group, byte[] value) {
        FeatureGroup featureGroup = this.makeGroup(group);
        BaseFeature feature = this.utils.makeFea(group.ordinal(), value);
        this.featureMap.put(featureGroup, feature);
    }
    
}
