<?php

declare(strict_types=1);

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

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

        foreach ($model->udaje->zoznamPoctuKontrolPodlaStavu() as $item) {
            $sourceItem = new PocetKontrolPodlaStavuEChartSourceItem();
            $sourceItem->add($item);
            $eChartSource->addItem($sourceItem);
        }

        return $eChartSource;
    }
}
