<?php

declare(strict_types=1);

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

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

        foreach ($model->udaje->zoznamPoctuKontrolAObratuPodlaSubjektuFakturacie() as $item) {
            $sourceItem = new PocetKontrolAObratuPodlaSubjektuFakturacieEChartSourceItem($item->nazovSubjektu());
            $sourceItem->add($item);
            $eChartSource->addItem($sourceItem);
        }

        return $eChartSource;
    }
}
