package org.jeecg.modules.adweb.marketing.googleads.vo;

import lombok.Data;

import org.jeecg.modules.adweb.common.constant.NumConstant;
import org.jeecg.modules.adweb.common.util.NumberUtil;
import org.jeecg.modules.adweb.marketing.googleads.dto.MetricsDTO;

import java.util.Map;

/**
 * @author wfansh
 */
@Data
public class KeywordStatsVO {

    private String keyword; // 关键词

    private long impressions; // 展示数

    private long clicks; // 点击数

    private double cost; // 花费

    public static KeywordStatsVO fromMetricsDTO(Map.Entry<String, MetricsDTO> metricsDTOEntry) {
        KeywordStatsVO keywordStatsVO = new KeywordStatsVO();

        keywordStatsVO.setKeyword(metricsDTOEntry.getKey());

        MetricsDTO metricsDTO = metricsDTOEntry.getValue();
        keywordStatsVO.setImpressions(metricsDTO.getImpressions());
        keywordStatsVO.setClicks(metricsDTO.getClicks());
        keywordStatsVO.setCost(
                NumberUtil.formatDecimal(
                                NumberUtil.safeDivide(
                                        metricsDTO.getCostMicros(), NumConstant.ONE_MILLION),
                                2)
                        .doubleValue());

        return keywordStatsVO;
    }
}
