<?php

declare(strict_types=1);

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

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 PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidlaDataTableBuilder
 *
 * @package Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\DataTables\Pracovisko\PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla
 */
final class PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidlaDataTableBuilder 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 PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidlaDataTable();

        foreach ($model->udaje->zoznamPoctuKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla() as $item) {
            $row = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidlaDataTableRow($item->druhPaliva(), $item->emisnySystem());
            $row->add($item);
            $dataTable->addRow($row);
        }

        return $dataTable;
    }
}
