<?php

declare(strict_types=1);

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

use Seka\Portal\Modul\Statistiky\Entities\Zaznam\Zaznam;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\DataTables\DataTableBuilderContract;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\DataTables\DataTableContract;

/**
 * Class PocetKontrolAObratuPodlaSubjektuFakturacieDataTableBuilder
 *
 * @package Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\DataTables\Pracovisko\PocetKontrolAObratuPodlaSubjektuFakturacie
 */
final class PocetKontrolAObratuPodlaSubjektuFakturacieDataTableBuilder implements DataTableBuilderContract
{
    /**
     * @param \Seka\Portal\Modul\Statistiky\Entities\Zaznam\Zaznam $model
     *
     * @return \Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\DataTables\DataTableContract
     */
    public static function build(Zaznam $model): DataTableContract
    {
        $dataTable = new PocetKontrolAObratuPodlaSubjektuFakturacieDataTable();

        foreach ($model->udaje->zoznamPoctuKontrolAObratuPodlaSubjektuFakturacie() as $item) {
            $row = new PocetKontrolAObratuPodlaSubjektuFakturacieDataTableRow($item->nazovSubjektu());
            $row->add($item);
            $dataTable->addRow($row);
        }

        return $dataTable;
    }
}
