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.CustomerStatsDTO;

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

    private String customerId; // 帐户ID

    private String descriptiveName; // 帐户名称

    private String currencyCode; // 币种

    private double conversions; // 转化数

    private double cost; // 总花费

    private double balance; // 帐户余额

    // See https://developers.google.com/google-ads/api/docs/recommendations.
    private double optiScore; // 优化得分

    public static CustomerStatsVO fromCustomerStatsDTO(CustomerStatsDTO customerStatsDTO) {
        CustomerStatsVO customerStatsVO = new CustomerStatsVO();

        customerStatsVO.setCustomerId(customerStatsDTO.getCustomerId());
        customerStatsVO.setDescriptiveName(customerStatsDTO.getDescriptiveName());
        customerStatsVO.setCurrencyCode(customerStatsDTO.getCurrencyCode());

        customerStatsVO.setConversions(
                NumberUtil.formatDecimal(customerStatsDTO.getConversions(), 2).doubleValue());
        customerStatsVO.setCost(
                NumberUtil.formatDecimal(
                                NumberUtil.safeDivide(
                                        customerStatsDTO.getCostMicros(), NumConstant.ONE_MILLION),
                                2)
                        .doubleValue());
        customerStatsVO.setBalance(
                NumberUtil.formatDecimal(
                                NumberUtil.safeDivide(
                                        customerStatsDTO.getBalanceMicros(),
                                        NumConstant.ONE_MILLION),
                                2)
                        .doubleValue());

        customerStatsVO.setOptiScore(
                NumberUtil.formatDecimal(customerStatsDTO.getOptiScore(), 4).doubleValue());

        return customerStatsVO;
    }
}
