<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\Pracovisko\PocetKontrolPodlaEmisnehoSystemuVozidla;

use Seka\Portal\Modul\Statistiky\Entities\Zaznam\Zaznam;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\EChartSourceBuilderContract;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\EChartSourceContract;

/**
 * Class PocetKontrolPodlaEmisnehoSystemuVozidlaEChartSourceBuilder
 *
 * @package Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\Pracovisko\PocetKontrolPodlaEmisnehoSystemuVozidla
 */
final class PocetKontrolPodlaEmisnehoSystemuVozidlaEChartSourceBuilder implements EChartSourceBuilderContract
{
    /**
     * @param \Seka\Portal\Modul\Statistiky\Entities\Zaznam\Zaznam $model
     *
     * @return \Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\EChartSourceContract
     */
    public static function build(Zaznam $model): EChartSourceContract
    {
        $eChartSource = new PocetKontrolPodlaEmisnehoSystemuVozidlaEChartSource();

        foreach ($model->udaje->zoznamPoctuKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla() as $item) {
            $sourceItem = new PocetKontrolPodlaEmisnehoSystemuVozidlaEChartSourceItem($item->druhPaliva(), $item->emisnySystem());
            $sourceItem->add($item);
            $eChartSource->addItem($sourceItem);
        }

        return $eChartSource;
    }
}
