<?php

declare(strict_types=1);

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

use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\DataTables\DataTableAbstract;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\DataTables\DataTableRowContract;

/**
 * Class PocetKontrolPodlaDruhuAHodnoteniaDataTable
 *
 * @package Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\DataTables\Pracovisko\PocetKontrolpodlaDruhuAHodnotenia
 */
final class PocetKontrolPodlaDruhuAHodnoteniaDataTable extends DataTableAbstract
{
    public function addRow(DataTableRowContract $row): self
    {
        $addIt = true;

        if (!empty($this->rows)) {
            foreach ($this->rows as $existRow) {
                if ($existRow->druh()->equal($row->druh())) {
                    $existRow->incrementData($row->druh(), $row->hodnotenia());
                    $addIt = false;
                    break;
                }
            }
        }

        if ($addIt) $this->rows[] = $row;

        return $this;
    }
}
