<?php

namespace Ignite\Core\Models\Dashboard\Charts;

use Ignite\Core\Services\Google\Analytics\Client;

class PageviewsStat extends BaseGoogleAnalyticsMetric
{
    /**
     * Create a new stat instance.
     *
     * @param array|object $attributes
     * @param Client $analytics
     */
    public function __construct(Client $analytics, $attributes = [])
    {
        $attributes = array_merge([
            'label' => 'Pageviews',
        ], $attributes);

        parent::__construct($analytics, $attributes);
    }


    /**
     * The HTML element ID.
     *
     * @return string
     */
    public function getElement()
    {
        return $this->get('key', 'pageviews-stat');
    }

    /**
     * The chart size in the layout.
     *
     * @return string
     */
    public function getSize()
    {
        return $this->get('size', 'col-xs-6 col-sm-3');
    }

    /**
     * Get the correct data value from storage.
     *
     * @return int
     * @throws \Google_Exception
     */
    public function getData()
    {
        return $this->prepareData('pageviews');
    }

    /**
     * @inheritDoc
     */
    protected function decorate($value)
    {
        return number_format($value);
    }
}
