package com.tzld.piaoquan.ad.engine.service.score.convert;

import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdActionFeature;
import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdItemFeature;
import com.tzld.piaoquan.recommend.feature.domain.ad.base.UserAdFeature;
import com.tzld.piaoquan.recommend.feature.model.feature.*;

/**
 * @author dyp
 */
public class FeatureConvert {

    public static UserAdFeatureProto convertToProto(UserAdFeature userAdFeature) {
        UserAdFeatureProto.Builder builder = UserAdFeatureProto.newBuilder();
        builder.setMid(userAdFeature.getMid());

        builder.setDay1CntFeatures(convertToProto(userAdFeature.getDay1_cnt_features()));
        builder.setDay3CntFeatures(convertToProto(userAdFeature.getDay3_cnt_features()));
        builder.setDay7CntFeatures(convertToProto(userAdFeature.getDay7_cnt_features()));
        builder.setMonth3CntFeatures(convertToProto(userAdFeature.getMonth3_cnt_features()));

        //TODO

        return builder.build();
    }

    public static UserAdFeature convertToJava(UserAdFeatureProto userAdFeatureProto) {
        UserAdFeature userAdFeature = new UserAdFeature();
        userAdFeature.setMid(userAdFeatureProto.getMid());

        userAdFeature.setDay1_cnt_features(convertToJava(userAdFeatureProto.getDay1CntFeatures()));
        userAdFeature.setDay3_cnt_features(convertToJava(userAdFeatureProto.getDay3CntFeatures()));
        userAdFeature.setDay7_cnt_features(convertToJava(userAdFeatureProto.getDay7CntFeatures()));
        userAdFeature.setMonth3_cnt_features(convertToJava(userAdFeatureProto.getMonth3CntFeatures()));

        return userAdFeature;
    }

    public static AdActionFeatureProto convertToProto(AdActionFeature adActionFeature) {
        AdActionFeatureProto.Builder builder = AdActionFeatureProto.newBuilder();
        builder.setAdView(adActionFeature.getAdView());
        builder.setAdClick(adActionFeature.getAdClick());
        builder.setAdConversion(adActionFeature.getAdConversion());
        builder.setCtr(adActionFeature.getCtr());
        builder.setCvr(adActionFeature.getCvr());
        return builder.build();
    }

    public static AdActionFeature convertToJava(AdActionFeatureProto adActionFeatureProto) {
        AdActionFeature adActionFeature = new AdActionFeature();
        adActionFeature.setAdView(adActionFeatureProto.getAdView());
        adActionFeature.setAdClick(adActionFeatureProto.getAdClick());
        adActionFeature.setAdConversion(adActionFeatureProto.getAdConversion());
        adActionFeature.setCtr(adActionFeatureProto.getCtr());
        adActionFeature.setCvr(adActionFeatureProto.getCvr());
        return adActionFeature;
    }

    public static AdItemFeature convertToJava(AdItemFeatureProto adItemFeatureProto) {
        AdItemFeature adItemFeature = new AdItemFeature();
        adItemFeature.setAdId(adItemFeatureProto.getAdId());
        adItemFeature.setAdCode(adItemFeatureProto.getAdCode());
        adItemFeature.setAdvertiserId(adItemFeatureProto.getAdvertiserId());
        adItemFeature.setAdvertiserCode(adItemFeatureProto.getAdvertiserCode());
        adItemFeature.setCampaignId(adItemFeatureProto.getCampaignId());
        adItemFeature.setCampaignCode(adItemFeatureProto.getCampaignCode());
        adItemFeature.setCreativeId(adItemFeatureProto.getCreativeId());
        //TODO 补充creative advertiser等维度信息
        adItemFeature.setDay1_cnt_features(convertToJava(adItemFeatureProto.getDay1CntFeatures()));
        adItemFeature.setDay3_cnt_features(convertToJava(adItemFeatureProto.getDay3CntFeatures()));
        adItemFeature.setDay7_cnt_features(convertToJava(adItemFeatureProto.getDay7CntFeatures()));
        adItemFeature.setMonth3_cnt_features(convertToJava(adItemFeatureProto.getMonth3CntFeatures()));

        adItemFeature.setCreative_1day_cnt_features(convertToJava(adItemFeatureProto.getCreative1DayCntFeatures()));
        adItemFeature.setCreative_3day_cnt_features(convertToJava(adItemFeatureProto.getCreative3DayCntFeatures()));
        adItemFeature.setCreative_7day_cnt_features(convertToJava(adItemFeatureProto.getCreative7DayCntFeatures()));
        adItemFeature.setCreative_3month_cnt_features(convertToJava(adItemFeatureProto.getCreative3MonthCntFeatures()));

        adItemFeature.setAdvertiser_1day_cnt_features(convertToJava(adItemFeatureProto.getAdvertiser1DayCntFeatures()));
        adItemFeature.setAdvertiser_3day_cnt_features(convertToJava(adItemFeatureProto.getAdvertiser3DayCntFeatures()));
        adItemFeature.setAdvertiser_7day_cnt_features(convertToJava(adItemFeatureProto.getAdvertiser7DayCntFeatures()));
        adItemFeature.setAdvertiser_3month_cnt_features(convertToJava(adItemFeatureProto.getAdvertiser3MonthCntFeatures()));



        return adItemFeature;

    }


    public static AdItemFeatureProto convertToProto(AdItemFeature adItemFeature) {
        AdItemFeatureProto.Builder builder = AdItemFeatureProto.newBuilder();
        builder.setAdId(adItemFeature.getAdId());
        builder.setAdCode(adItemFeature.getAdCode());
        builder.setAdvertiserId(adItemFeature.getAdvertiserId());
        builder.setAdvertiserCode(adItemFeature.getAdvertiserCode());
        builder.setCampaignId(adItemFeature.getCampaignId());
        builder.setCampaignCode(adItemFeature.getCampaignCode());
        builder.setCreativeId(adItemFeature.getCreativeId());
        builder.setCreativeCode(adItemFeature.getCreativeCode());
        builder.setDay1CntFeatures(convertToProto(adItemFeature.getDay1_cnt_features()));
        builder.setDay3CntFeatures(convertToProto(adItemFeature.getDay3_cnt_features()));
        builder.setDay7CntFeatures(convertToProto(adItemFeature.getDay7_cnt_features()));
        builder.setMonth3CntFeatures(convertToProto(adItemFeature.getMonth3_cnt_features()));

        builder.setCreative1DayCntFeatures(convertToProto(adItemFeature.getCreative_1day_cnt_features()));
        builder.setCreative3DayCntFeatures(convertToProto(adItemFeature.getCreative_3day_cnt_features()));
        builder.setCreative7DayCntFeatures(convertToProto(adItemFeature.getCreative_7day_cnt_features()));
        builder.setCreative3MonthCntFeatures(convertToProto(adItemFeature.getCreative_3month_cnt_features()));

        builder.setAdvertiser1DayCntFeatures(convertToProto(adItemFeature.getAdvertiser_1day_cnt_features()));
        builder.setAdvertiser3DayCntFeatures(convertToProto(adItemFeature.getAdvertiser_3day_cnt_features()));
        builder.setAdvertiser7DayCntFeatures(convertToProto(adItemFeature.getAdvertiser_7day_cnt_features()));
        builder.setAdvertiser3MonthCntFeatures(convertToProto(adItemFeature.getAdvertiser_3month_cnt_features()));

        return builder.build();
    }
}
