<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary;

use Illuminate\Support\Str;
use League\Fractal\TransformerAbstract;
use Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects\UdajePreTypZaznamuPouzivatel;
use Seka\Portal\Modul\Statistiky\Entities\Zaznam\Zaznam;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\EChartSourceItemContract;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\Technik\PocetKontrolPodlaDruhu\PocetKontrolPodlaDruhuEChartSourceItem;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\Technik\PocetKontrolPodlaEmisnehoSystemuVozidla\PocetKontrolPodlaEmisnehoSystemuVozidlaEChartSourceItem;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\Technik\PocetKontrolPodlaHodnotenia\PocetKontrolPodlaHodnoteniaEChartSourceItem;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\Technik\PocetKontrolPodlaKategorieVozidla\PocetKontrolPodlaKategorieVozidlaEChartSourceItem;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\Technik\PocetKontrolPodlaStavu\PocetKontrolPodlaStavuEChartSourceItem;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\Technik\PocetKontrolSObratom\PocetKontrolSObratomEChartSourceItem;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\TransformerContract;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\TransformerTrait;

/**
 * Class ZaznamTechnikSummaryEChartsDataTransformer
 *
 * @package Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary
 */
final class ZaznamTechnikSummaryEChartsDataTransformer extends TransformerAbstract implements TransformerContract
{
    use TransformerTrait;

    /**
     * @param \Seka\Portal\Modul\Statistiky\Entities\Zaznam\Zaznam $model
     *
     * @return array
     * @throws \Seka\Portal\Modul\Statistiky\Exceptions\NeznamiDruhUdajovZaznamuException
     */
    public function transform(Zaznam $model): array
    {
        $this->checkUdajeType($model, UdajePreTypZaznamuPouzivatel::class);

        $out = [];

        foreach (get_class_methods($this) as $method) {
            if (Str::startsWith($method, 'transformujUdaje')) {
                $dt = $this->$method($model);
                $out[class_basename($dt)] = $dt;
            }
        }

        return $out;
    }

    /**
     * @param \Seka\Portal\Modul\Statistiky\Entities\Zaznam\Zaznam $model
     *
     * @return \Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\EChartSourceItemContract
     */
    protected function transformujUdajeZoznamPoctuKontrolAObratuPodlaSubjektuFakturacie(Zaznam $model): EChartSourceItemContract
    {
        $item = new PocetKontrolSObratomEChartSourceItem($model->subjekt->nazov());

        foreach ($model->udaje->zoznamPoctuKontrolSObratom() as $pk) {
            $item->add($pk);
        }

        return $item;
    }

    /**
     * @param \Seka\Portal\Modul\Statistiky\Entities\Zaznam\Zaznam $model
     *
     * @return \Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\EChartSourceItemContract
     */
    protected function transformujUdajeZoznamPoctuKontrolPodlaStavu(Zaznam $model): EChartSourceItemContract
    {
        $item = new PocetKontrolPodlaStavuEChartSourceItem($model->subjekt->nazov());

        foreach ($model->udaje->zoznamPoctuKontrolPodlaStavu() as $pk) {
            $item->add($pk);
        }

        return $item;
    }

    /**
     * @param \Seka\Portal\Modul\Statistiky\Entities\Zaznam\Zaznam $model
     *
     * @return \Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\EChartSourceItemContract
     */
    protected function transformujUdajeZoznamPoctuKontrolPodlaEmisnehoSystemuVozidla(Zaznam $model): EChartSourceItemContract
    {
        $item = new PocetKontrolPodlaEmisnehoSystemuVozidlaEChartSourceItem($model->subjekt->nazov());

        foreach ($model->udaje->zoznamPoctuKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla() as $pk) {
            $item->add($pk);
        }

        return $item;
    }

    /**
     * @param \Seka\Portal\Modul\Statistiky\Entities\Zaznam\Zaznam $model
     *
     * @return \Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\EChartSourceItemContract
     */
    protected function transformujUdajeZoznamPoctuKontrolPodlaKategorieVozidla(Zaznam $model): EChartSourceItemContract
    {
        $item = new PocetKontrolPodlaKategorieVozidlaEChartSourceItem($model->subjekt->nazov());

        foreach ($model->udaje->zoznamPoctuKontrolPodlaKategorieVozidla() as $pk) {
            $item->add($pk);
        }

        return $item;
    }

    /**
     * @param \Seka\Portal\Modul\Statistiky\Entities\Zaznam\Zaznam $model
     *
     * @return \Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\EChartSourceItemContract
     */
    protected function transformujUdajeZoznamPoctuKontrolPodlaDruhu(Zaznam $model): EChartSourceItemContract
    {
        $item = new PocetKontrolPodlaDruhuEChartSourceItem($model->subjekt->nazov());

        foreach ($model->udaje->zoznamPoctuKontrolPodlaDruhu() as $pk) {
            $item->add($pk);
        }

        return $item;
    }

    /**
     * @param \Seka\Portal\Modul\Statistiky\Entities\Zaznam\Zaznam $model
     *
     * @return \Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\EChartSourceItemContract
     */
    protected function transformujUdajeZoznamPoctuKontrolPodlaHodnotenia(Zaznam $model): EChartSourceItemContract
    {
        $item = new PocetKontrolPodlaHodnoteniaEChartSourceItem($model->subjekt->nazov());

        foreach ($model->udaje->zoznamPoctuKontrolPodlaHodnotenia() as $pk) {
            $item->add($pk);
        }

        return $item;
    }
}
