<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Terminy\Entities\Dtos\Factory;

use \App\Dtos\PouzivatelDto;
use \App\Dtos\PracoviskoDto;
use Seka\Portal\Modul\Terminy\Entities\Dtos\RegistraciaDTO;
use Seka\Portal\Modul\Terminy\Entities\Registracia\Registracia;

/**
 * Class RegistraciaDTOFactory
 *
 * @package Seka\Portal\Modul\Terminy\Entities\Dtos\Factory
 */
final class RegistraciaDTOFactory
{
    /**
     * @throws \ReflectionException
     */
    public static function make(Registracia $registracia): RegistraciaDTO
    {
        $model = $registracia->withoutRelations()->toArray();
        $pouzivatel = $registracia->pouzivatel;

        $model['vytvoril'] = new PouzivatelDto($registracia->vytvoril->toArray());
        $model['pouzivatel'] = $pouzivatel ? new PouzivatelDto($pouzivatel->toArray()) : null;
        $model['pracovisko'] = new PracoviskoDto($registracia->pracovisko->toArray());
        $model['udalost'] = UdalostDTOFactory::make($registracia->udalost);
        $model['moznosti'] = $registracia->moznosti->isNotEmpty() ? ZoznamZvolenychMoznostiDTOFactory::make($registracia->moznosti) : null;

        return new RegistraciaDTO($model);
    }
}
