<?php

declare(strict_types=1);

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

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 PocetKontrolPodlaKategorieVozidlaEChartSourceBuilder
 *
 * @package Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\Pracovisko\PocetKontrolPodlaKategorieVozidla
 */
final class PocetKontrolPodlaKategorieVozidlaEChartSourceBuilder 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 PocetKontrolPodlaKategorieVozidlaEChartSource();

        foreach ($model->udaje->zoznamPoctuKontrolPodlaKategorieVozidla() as $item) {
            $sourceItem = new PocetKontrolPodlaKategorieVozidlaEChartSourceItem($item->kategoria());
            $sourceItem->add($item);
            $eChartSource->addItem($sourceItem);
        }

        return $eChartSource;
    }
}
