# DO NOT EDIT THIS FILE!
#
# This file is generated from the CDP specification. If you need to make
# changes, edit the generator and regenerate all of the modules.
#
# CDP domain: Ads (experimental)
from __future__ import annotations
from .util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing

@dataclass
class AdMetrics:
    '''
    Ad metrics for a page.
    '''
    #: The viewport ad density by area, represented as a percentage (an integer
    #: between 0 and 100).
    viewport_ad_density_by_area: int

    #: The time-weighted average of the viewport ad density by area, measured
    #: across the duration of the page.
    average_viewport_ad_density_by_area: float

    #: The number of ads currently visible within the viewport.
    viewport_ad_count: int

    #: The time-weighted average of the viewport ad count, measured across the
    #: duration of the page.
    average_viewport_ad_count: float

    #: The total ad CPU usage, in milliseconds.
    total_ad_cpu_time: float

    #: The total ad network bytes.
    total_ad_network_bytes: float

    def to_json(self):
        json = dict()
        json['viewportAdDensityByArea'] = self.viewport_ad_density_by_area
        json['averageViewportAdDensityByArea'] = self.average_viewport_ad_density_by_area
        json['viewportAdCount'] = self.viewport_ad_count
        json['averageViewportAdCount'] = self.average_viewport_ad_count
        json['totalAdCpuTime'] = self.total_ad_cpu_time
        json['totalAdNetworkBytes'] = self.total_ad_network_bytes
        return json

    @classmethod
    def from_json(cls, json):
        return cls(
            viewport_ad_density_by_area=int(json['viewportAdDensityByArea']),
            average_viewport_ad_density_by_area=float(json['averageViewportAdDensityByArea']),
            viewport_ad_count=int(json['viewportAdCount']),
            average_viewport_ad_count=float(json['averageViewportAdCount']),
            total_ad_cpu_time=float(json['totalAdCpuTime']),
            total_ad_network_bytes=float(json['totalAdNetworkBytes']),
        )


def get_ad_metrics() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,AdMetrics]:
    '''
    Retrieves ad metrics for the current page.

    :returns: 
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'Ads.getAdMetrics',
    }
    json = yield cmd_dict
    return AdMetrics.from_json(json['metrics'])
