<?php

declare(strict_types=1);

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

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

        foreach ($model->udaje->zoznamPoctuKontrolPodlaDruhuAHodnotenia() as $item) {
            $sourceItem = new PocetKontrolPodlaDruhuAHodnoteniaEChartSourceItem($item->druh());
            $sourceItem->add($item);
            $eChartSource->addItem($sourceItem);
        }

        return $eChartSource;
    }
}
